結果

問題 No.140 みんなで旅行
ユーザー kyunakyuna
提出日時 2019-08-19 19:04:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,948 ms / 5,000 ms
コード長 811 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 76,864 KB
実行使用メモリ 22,580 KB
最終ジャッジ日時 2024-04-15 06:37:59
合計ジャッジ時間 15,628 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 26 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2,948 ms
22,548 KB
testcase_12 AC 15 ms
6,944 KB
testcase_13 AC 3 ms
6,948 KB
testcase_14 AC 2,888 ms
22,580 KB
testcase_15 AC 2,836 ms
22,400 KB
testcase_16 AC 608 ms
10,760 KB
testcase_17 AC 197 ms
6,944 KB
testcase_18 AC 1,831 ms
18,184 KB
testcase_19 AC 2,295 ms
19,740 KB
testcase_20 AC 135 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int MOD = (int)1e9 + 7;

int main() {
    int n; cin >> n;
    vector<vector<ll>> dp(n * 2 + 1, vector<ll>(n * 2 + 1));
    dp[0][0] = 1;
	for (int t = 0; t < n; t++) {
        vector<vector<ll>> dp2(n * 2 + 1, vector<ll>(n * 2 + 1));
		for (int i = 0; i <= t * 2; i++) {
			for (int j = 0; i + j <= t * 2; j++) {
				(dp2[i][j + 2] += dp[i][j]) %= MOD;
				(dp2[i][j + 1] += dp[i][j] * (i + j) * 2) %= MOD;
				(dp2[i][j] += dp[i][j] * ((i + j) * (i + j) - j)) %= MOD;
				(dp2[i + 1][j] += dp[i][j]) %= MOD;
				if (j) (dp2[i + 1][j - 1] += dp[i][j] * j) %= MOD;
			}
		}
        swap(dp, dp2);
	}
	long long ans = 0;
	for (int i = 0; i <= n * 2; i++) (ans += dp[i][0]) %= MOD;
	cout << ans << endl;
}
0