結果

問題 No.140 みんなで旅行
ユーザー 👑 kmjpkmjp
提出日時 2014-12-22 01:10:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 982 bytes
コンパイル時間 1,136 ms
コンパイル使用メモリ 144,632 KB
実行使用メモリ 27,292 KB
最終ジャッジ日時 2023-09-02 21:19:31
合計ジャッジ時間 3,006 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
26,996 KB
testcase_01 AC 36 ms
27,128 KB
testcase_02 AC 36 ms
27,060 KB
testcase_03 AC 36 ms
27,016 KB
testcase_04 AC 35 ms
26,976 KB
testcase_05 AC 35 ms
27,124 KB
testcase_06 AC 36 ms
26,996 KB
testcase_07 AC 36 ms
27,008 KB
testcase_08 AC 36 ms
27,016 KB
testcase_09 AC 36 ms
27,204 KB
testcase_10 AC 36 ms
27,068 KB
testcase_11 AC 41 ms
26,976 KB
testcase_12 AC 36 ms
27,188 KB
testcase_13 AC 36 ms
27,060 KB
testcase_14 AC 41 ms
27,064 KB
testcase_15 AC 41 ms
27,012 KB
testcase_16 AC 38 ms
27,068 KB
testcase_17 AC 37 ms
27,292 KB
testcase_18 AC 40 ms
27,064 KB
testcase_19 AC 39 ms
27,200 KB
testcase_20 AC 36 ms
27,292 KB
testcase_21 AC 36 ms
27,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll mo=1000000007;
ll C[1005][1005], P[1005][1005], Q[1005][1005];

int main(int argc,char** argv){
	int x,y,z;
	
	cin>>N;
	for(x = 0; x < 1002; x++) {
		C[x][0]=1;
		for(y = 1; y <= x; y++) C[x][y] = (C[x-1][y] + C[x-1][y-1]) % mo;
	}
	
	for(x = 1; x < 1002; x++) {
		P[x][1]=1;
		for(y = 2; y <= x; y++) P[x][y] = (P[x-1][y-1] + y * P[x-1][y]) % mo;
	}
	for(y = 0; y < 1002; y++) {
		Q[y][0] = 1;
		for(z = 0; z <= 1002; z++) Q[y][z+1] = Q[y][z] * y * (y-1) % mo;
	}
	
	ll ret = 0;
	for(x = 1; x <= N; x++)
		for(y = 1; y <= x; y++)
			ret = (ret + C[N][x] * P[x][y] % mo * Q[y][N-x]) % mo;
	
	cout << ret << endl;
}
0