結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 WA -
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,948 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
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 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
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];
//pow[i][j] := 夫婦が同じグループに属しているのがi組の時、 ほかの夫婦が別々に分かれる場合の数
// ll pow[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[0][0] = 1;
	for (int i = 1; i <= n; ++i){
		for (int j = 1; 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