結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,812 KB
testcase_02 AC 17 ms
6,812 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1,816 ms
22,656 KB
testcase_12 AC 9 ms
6,940 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 1,820 ms
22,528 KB
testcase_15 AC 1,766 ms
22,400 KB
testcase_16 AC 351 ms
10,752 KB
testcase_17 AC 109 ms
7,168 KB
testcase_18 AC 1,075 ms
18,176 KB
testcase_19 AC 1,451 ms
19,840 KB
testcase_20 AC 77 ms
6,940 KB
testcase_21 AC 3 ms
6,940 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));
    vector<vector<ll>> dp2(n * 2 + 1, vector<ll>(n * 2 + 1));
    dp[0][0] = 1;
	for (int t = 0; t < n; t++) {
		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);
        dp2.assign(n * 2 + 1, vector<ll>(n * 2 + 1));
	}
	long long ans = 0;
	for (int i = 0; i <= n * 2; i++) (ans += dp[i][0]) %= MOD;
	cout << ans << endl;
}
0