結果

問題 No.140 みんなで旅行
ユーザー pekempeypekempey
提出日時 2015-11-12 23:20:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,191 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 145,172 KB
実行使用メモリ 9,232 KB
最終ジャッジ日時 2023-10-11 15:45:23
合計ジャッジ時間 2,886 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,928 KB
testcase_01 AC 5 ms
8,980 KB
testcase_02 AC 6 ms
8,912 KB
testcase_03 AC 5 ms
8,920 KB
testcase_04 AC 5 ms
8,988 KB
testcase_05 AC 5 ms
8,916 KB
testcase_06 AC 5 ms
8,992 KB
testcase_07 AC 5 ms
8,908 KB
testcase_08 AC 5 ms
8,980 KB
testcase_09 AC 5 ms
8,924 KB
testcase_10 AC 5 ms
9,228 KB
testcase_11 AC 10 ms
8,912 KB
testcase_12 AC 5 ms
9,048 KB
testcase_13 AC 5 ms
8,916 KB
testcase_14 AC 9 ms
9,044 KB
testcase_15 AC 10 ms
8,988 KB
testcase_16 AC 7 ms
8,928 KB
testcase_17 AC 6 ms
9,116 KB
testcase_18 AC 9 ms
8,920 KB
testcase_19 AC 9 ms
9,232 KB
testcase_20 AC 6 ms
8,924 KB
testcase_21 AC 5 ms
8,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;
ll C[600][600];
ll S[600][600];

ll modpow(ll a, ll b, ll mod) {
	ll res = 1;
	while (b) {
		if (b & 1) (res *= a) %= mod;
		(a *= a) %= mod;
		b /= 2;
	}
	return res;
}

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

	C[0][0] = 1;
	rep (i, 1, 600) {
		C[i][0] = 1;
		rep (j, 1, 600) {
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
		}
	}

	rep (i, 1, 600) {
		S[i][1] = S[i][i] = 1;
		rep (j, 2, i) {
			S[i][j] = (S[i - 1][j - 1] + j * S[i - 1][j]) % mod;
		}
	}

	ll ans = 0;
	rep (i, 1, n + 1) {
		rep (j, 1, i + 1) {
			ans += C[n][i] * S[i][j] % mod * modpow(j * (j - 1), n - i, mod);
			ans %= mod;
		}
	}
	cout << ans << endl;
	return 0;
}
0