結果

問題 No.336 門松列列
ユーザー mamekinmamekin
提出日時 2016-10-09 20:34:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,347 bytes
コンパイル時間 1,101 ms
コンパイル使用メモリ 106,120 KB
実行使用メモリ 35,168 KB
最終ジャッジ日時 2023-09-02 18:45:15
合計ジャッジ時間 1,939 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
28,536 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 41 ms
35,168 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 6 ms
6,912 KB
testcase_07 AC 15 ms
14,356 KB
testcase_08 AC 27 ms
23,504 KB
testcase_09 AC 40 ms
33,868 KB
testcase_10 AC 41 ms
34,864 KB
testcase_11 AC 41 ms
35,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const int MOD      = 1000000007;
const int MOD_INV4 =  250000002;

void combination(int n, vector<vector<long long> >& comb)
{
    comb.assign(n+1, vector<long long>(n+1, 0));
    for(int i=0; i<=n; ++i){
        comb[i][0] = 1;
        for(int j=1; j<=i; ++j)
            comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % MOD;
    }
}

int main()
{
    int n;
    cin >> n;
    if(n < 3){
        cout << 0 << endl;
        return 0;
    }

    vector<vector<long long> > comb;
    combination(n, comb);

    vector<long long> dp(n+1, 0);
    dp[0] = dp[1] = dp[2] = 2;
    for(int i=3; i<=n; ++i){
        for(int j=0; j<i; ++j){
            long long tmp = dp[j] * dp[i-j-1];
            tmp %= MOD;
            tmp *= MOD_INV4;
            tmp %= MOD;
            tmp *= comb[i-1][j];
            dp[i] += tmp;
            dp[i] %= MOD;
        }
    }
    cout << dp[n] << endl;

    return 0;
}
0