結果

問題 No.140 みんなで旅行
ユーザー ttkkggwwttkkggww
提出日時 2022-05-11 20:44:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,142 bytes
コンパイル時間 4,534 ms
コンパイル使用メモリ 265,580 KB
実行使用メモリ 14,020 KB
最終ジャッジ日時 2023-09-26 11:44:48
合計ジャッジ時間 21,284 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
6,796 KB
testcase_01 AC 12 ms
6,676 KB
testcase_02 AC 454 ms
8,320 KB
testcase_03 AC 3 ms
5,420 KB
testcase_04 AC 16 ms
6,788 KB
testcase_05 AC 20 ms
6,676 KB
testcase_06 AC 23 ms
6,792 KB
testcase_07 AC 27 ms
6,792 KB
testcase_08 AC 31 ms
6,656 KB
testcase_09 AC 35 ms
7,068 KB
testcase_10 AC 38 ms
7,036 KB
testcase_11 AC 2,332 ms
13,860 KB
testcase_12 AC 370 ms
8,208 KB
testcase_13 AC 207 ms
7,688 KB
testcase_14 WA -
testcase_15 AC 2,312 ms
13,952 KB
testcase_16 AC 1,349 ms
11,256 KB
testcase_17 AC 901 ms
10,008 KB
testcase_18 AC 2,008 ms
13,008 KB
testcase_19 AC 2,133 ms
13,364 KB
testcase_20 AC 787 ms
9,364 KB
testcase_21 AC 131 ms
7,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
using mint = modint1000000007;

int n;
//mint dp[556][556][556];

void solve(){
	vector<vector<vector<mint>>> dp(555+1);
	dp[0] = vector<vector<mint>>(555+1,vector<mint>(555+1));
	dp[1] = vector<vector<mint>>(555+1,vector<mint>(555+1));

	dp[1][1][1] = 1;
	dp[1][2][0] = 1;
	for(int i = 1;i<n;i++){
		dp[i+1] = vector<vector<mint>>(555+1,vector<mint>(555+1));
		for(int j = 0;j<555-1;j++){
			for(int k = 0;k<555+1;k++){
				dp[i+1][j][k+1] += dp[i][j][k] *(j-k);
				dp[i+1][j][k] += dp[i][j][k] *k;

				dp[i+1][j][k] += dp[i][j][k] * j*(j-1);

				dp[i+1][j+1][k+1] += dp[i][j][k];
				dp[i+1][j+1][k] += dp[i][j][k]*j*2;
				dp[i+1][j+2][k] += dp[i][j][k];
			}
		}
		dp[i].clear();
	}
	mint ans = 0;
	for(int i = 0;i<=n;i++){
		//cerr<<i<<':'<<dp[n][i][i].val()<<endl;
		ans += dp[n][i][i];
	}
	/*
	for(int i = 0;i<10;i++){
		for(int j = 0;j<10;j++){
			cerr<<dp[2][i][j].val()<<' ';
		}
		cout<<endl;
	}
	*/
	cout<<ans.val()<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n;
	solve();
}
0