結果

問題 No.140 みんなで旅行
ユーザー eitahoeitaho
提出日時 2015-12-05 23:04:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 385 ms / 5,000 ms
コード長 538 bytes
コンパイル時間 469 ms
コンパイル使用メモリ 10,760 KB
実行使用メモリ 22,568 KB
最終ジャッジ日時 2023-10-12 15:50:18
合計ジャッジ時間 5,118 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,860 KB
testcase_01 AC 17 ms
7,816 KB
testcase_02 AC 32 ms
8,760 KB
testcase_03 AC 17 ms
7,860 KB
testcase_04 AC 16 ms
7,864 KB
testcase_05 AC 17 ms
7,916 KB
testcase_06 AC 17 ms
7,768 KB
testcase_07 AC 17 ms
7,800 KB
testcase_08 AC 17 ms
7,884 KB
testcase_09 AC 16 ms
7,848 KB
testcase_10 AC 16 ms
7,936 KB
testcase_11 AC 385 ms
22,568 KB
testcase_12 AC 27 ms
8,576 KB
testcase_13 AC 19 ms
8,340 KB
testcase_14 AC 374 ms
22,456 KB
testcase_15 AC 382 ms
22,472 KB
testcase_16 AC 150 ms
13,624 KB
testcase_17 AC 77 ms
10,588 KB
testcase_18 AC 302 ms
19,396 KB
testcase_19 AC 337 ms
20,360 KB
testcase_20 AC 64 ms
10,236 KB
testcase_21 AC 19 ms
7,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Mod = int(1e9) + 7
N = int(input())
C = [[0] * (N + 1) for r in range(N + 1)]
dp = [[0] * (N + 1) for r in range(N + 1)]
dp[0][0] = 1
ans = 0

for r in range(N + 1):
    C[r][0] = C[r][r] = 1
    for c in range(1, r):
        C[r][c] = (C[r - 1][c] + C[r - 1][c - 1]) % Mod
for pair in range(1, N + 1):
    for num in range(1, pair + 1):
        dp[pair][num] = (dp[pair - 1][num - 1] + dp[pair - 1][num] * num) % Mod
        ans = (ans + dp[pair][num] * C[N][pair] *
               pow(num * (num - 1), N - pair, Mod)) % Mod

print(ans)
0