結果

問題 No.140 みんなで旅行
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-17 13:43:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,395 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 60,776 KB
実行使用メモリ 9,164 KB
最終ジャッジ日時 2024-04-28 15:19:50
合計ジャッジ時間 1,190 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int mod = 1e9 + 7;

//スターリング数 S(n, k) 区別できるn個のものを区別できないkグループに分類する方法の場合の数
//S[i][j] := i組の夫婦が同じグループに属し、合計yグループ作る場合の数
ll S[600][600];
//com[i][j] := iCj
ll com[600][600];

//x^k mod
ll powmod(ll x, ll k, ll m){
	if(k == 0) return 1;
	if(k % 2 == 0) return powmod(x * x % m, k / 2, m);
	else return x * powmod(x, k - 1, m) % m;
}

int main(void){
	int n; cin >> n;

	S[1][1] = 1;
	for (int i = 2; i <= n; ++i){
		for (int j = 2; j <= i; ++j){
			//スターリング数の漸化式
			S[i][j] = (S[i - 1][j - 1] + j * S[i - 1][j]) % mod;
		}
	}

	//combination
	com[0][0] = 1;
	for (int i = 1; i <= n; ++i){
		for (int j = 0; j <= i; ++j){
			//パスカルの3角形
			if(j == 0) com[i][j] = com[i - 1][j] % mod;
			else com[i][j] = (com[i - 1][j] + com[i - 1][j - 1]) % mod;
		}
	}

	ll sum = 0;
	for (int i = 1; i <= n; ++i){
		for (int j = 1; j <= i; ++j){
			//夫婦が同じグループに入るi組の選び方と、残りのn-	i組の夫婦の入れ方をかける
			sum += (com[n][i] * S[i][j]) % mod * powmod(j * (j - 1), n - i, mod) % mod;
			sum %= mod;
		}	
	}

	printf("%lld\n", sum % mod);
	return 0;
}
0