結果

問題 No.140 みんなで旅行
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-04 09:00:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,602 ms / 5,000 ms
コード長 839 bytes
コンパイル時間 1,135 ms
コンパイル使用メモリ 144,904 KB
実行使用メモリ 21,704 KB
最終ジャッジ日時 2023-09-17 04:11:27
合計ジャッジ時間 10,093 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,384 KB
testcase_01 AC 2 ms
5,448 KB
testcase_02 AC 22 ms
10,768 KB
testcase_03 AC 2 ms
5,420 KB
testcase_04 AC 2 ms
5,668 KB
testcase_05 AC 3 ms
5,688 KB
testcase_06 AC 2 ms
5,420 KB
testcase_07 AC 2 ms
5,472 KB
testcase_08 AC 2 ms
5,452 KB
testcase_09 AC 2 ms
5,484 KB
testcase_10 AC 2 ms
5,520 KB
testcase_11 AC 1,578 ms
21,704 KB
testcase_12 AC 13 ms
8,400 KB
testcase_13 AC 4 ms
7,952 KB
testcase_14 AC 1,598 ms
21,664 KB
testcase_15 AC 1,602 ms
21,608 KB
testcase_16 AC 385 ms
17,608 KB
testcase_17 AC 129 ms
15,152 KB
testcase_18 AC 1,076 ms
20,920 KB
testcase_19 AC 1,260 ms
21,172 KB
testcase_20 AC 90 ms
13,088 KB
testcase_21 AC 3 ms
7,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

long long dp[557 * 2][557 * 2];
long long dp2[557 * 2][557 * 2];
long long mod = (int)(1e9) + 7;

int main() {
	int N;
	cin >> N;
	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++)
			{
				if (j != 0) dp2[i + 1][j - 1] += dp[i][j] * j;
				dp2[i][j + 2] += dp[i][j];
				dp2[i][j + 1] += dp[i][j] * ((i + j) * 2);
				dp2[i + 1][j] += dp[i][j];
				dp2[i][j] += dp[i][j] * ((i + j) * (i + j) - j);
			}
		}

		for (int i = 0; i <= (t + 1) * 2; i++)
		{
			for (int j = 0; i + j <= (t + 1) * 2; j++)
			{
				dp[i][j] = dp2[i][j] % mod;
				dp2[i][j] = 0;
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i <= N * 2; i++)
	{
		ans += dp[i][0];
	}
	ans %= mod;
	cout << ans << endl;

}
0