結果

問題 No.140 みんなで旅行
ユーザー chocoruskchocorusk
提出日時 2018-12-13 19:07:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 1,164 bytes
コンパイル時間 759 ms
コンパイル使用メモリ 97,664 KB
実行使用メモリ 15,512 KB
最終ジャッジ日時 2023-10-25 09:30:50
合計ジャッジ時間 1,822 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
15,512 KB
testcase_01 AC 10 ms
15,512 KB
testcase_02 AC 11 ms
15,512 KB
testcase_03 AC 10 ms
15,512 KB
testcase_04 AC 10 ms
15,512 KB
testcase_05 AC 10 ms
15,512 KB
testcase_06 AC 10 ms
15,512 KB
testcase_07 AC 10 ms
15,512 KB
testcase_08 AC 10 ms
15,512 KB
testcase_09 AC 10 ms
15,512 KB
testcase_10 AC 10 ms
15,512 KB
testcase_11 AC 16 ms
15,512 KB
testcase_12 AC 10 ms
15,512 KB
testcase_13 AC 10 ms
15,512 KB
testcase_14 AC 16 ms
15,512 KB
testcase_15 AC 16 ms
15,512 KB
testcase_16 AC 12 ms
15,512 KB
testcase_17 AC 11 ms
15,512 KB
testcase_18 AC 14 ms
15,512 KB
testcase_19 AC 15 ms
15,512 KB
testcase_20 AC 10 ms
15,512 KB
testcase_21 AC 10 ms
15,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
	int n;
	cin>>n;
	ll pow[556][1111];
	for(ll i=0; i<=n; i++){
		pow[i][0]=1;
		for(int j=1; j<=2*n; j++){
			pow[i][j]=pow[i][j-1]*i%MOD;
		}
	}
	ll comb[556][556]={};
	comb[0][0]=1;
	for(int i=1; i<=n; i++){
		comb[i][0]=comb[i][i]=1;
		for(int j=1; j<i; j++){
			comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%MOD;
		}
	}
	ll a[556][556];
	fill(a[1]+1, a[1]+n+1, 1);
	for(ll x=2; x<=n; x++){
		a[x][x]=1;
		for(int y=x+1; y<=n; y++){
			a[x][y]=(a[x-1][y-1]+x*a[x][y-1])%MOD;
		}
	}
	ll b[556][556];
	for(int x=1; x<=n; x++){
		for(int y=x; y<=n; y++){
			b[x][y]=pow[x][n-y]*pow[x-1][n-y]%MOD*a[x][y]%MOD;
		}
	}
	ll ans=0;
	for(int x=1; x<=n; x++){
		for(int y=x; y<=n; y++){
			ans+=(comb[n][y]*b[x][y]%MOD);
			ans%=MOD;
		}
	}
	cout<<ans<<endl;
	return 0;
}
0