結果

問題 No.140 みんなで旅行
ユーザー mamekinmamekin
提出日時 2015-02-01 02:56:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 633 ms / 5,000 ms
コード長 1,322 bytes
コンパイル時間 1,854 ms
コンパイル使用メモリ 92,708 KB
実行使用メモリ 13,420 KB
最終ジャッジ日時 2023-09-05 08:49:20
合計ジャッジ時間 4,954 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 9 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 633 ms
13,420 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 631 ms
13,336 KB
testcase_15 AC 632 ms
13,420 KB
testcase_16 AC 149 ms
7,260 KB
testcase_17 AC 50 ms
5,156 KB
testcase_18 AC 416 ms
11,184 KB
testcase_19 AC 486 ms
12,028 KB
testcase_20 AC 35 ms
4,580 KB
testcase_21 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#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>
using namespace std;

const int MOD = 1000000007;

int main()
{
    int n;
    cin >> n;

    vector<vector<long long> > dp(1, vector<long long>(1, 1));
    for(int i=0; i<n; ++i){
        vector<vector<long long> > nextDp(i+2, vector<long long>(2*i+3));
        for(int a=0; a<i+1; ++a){
            for(int b=0; b<2*i+1; ++b){
                nextDp[a][b] += dp[a][b] * ((a + b) * (a + b - 1) + a);
                nextDp[a][b+1] += dp[a][b] * (a + b) * 2;
                nextDp[a][b+2] += dp[a][b];
                nextDp[a+1][b] += dp[a][b];
                if(b > 0)
                    nextDp[a+1][b-1] += dp[a][b] * b;
            }
        }
        dp.swap(nextDp);
        for(int a=0; a<i+2; ++a){
            for(int b=0; b<2*i+3; ++b){
                dp[a][b] %= MOD;
            }
        }
    }

    long long ret = 0;
    for(int a=0; a<n+1; ++a){
        ret += dp[a][0];
        ret %= MOD;
    }
    cout << ret << endl;

    return 0;
}
0