結果

問題 No.140 みんなで旅行
ユーザー convexineqconvexineq
提出日時 2021-02-14 02:58:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,544 ms / 5,000 ms
コード長 795 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 276,608 KB
最終ジャッジ日時 2023-09-28 12:34:18
合計ジャッジ時間 15,481 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,196 KB
testcase_01 AC 75 ms
71,132 KB
testcase_02 AC 123 ms
77,676 KB
testcase_03 AC 72 ms
71,272 KB
testcase_04 AC 74 ms
71,372 KB
testcase_05 AC 72 ms
71,316 KB
testcase_06 AC 80 ms
71,292 KB
testcase_07 AC 74 ms
71,196 KB
testcase_08 AC 74 ms
71,160 KB
testcase_09 AC 75 ms
71,292 KB
testcase_10 AC 74 ms
71,148 KB
testcase_11 AC 2,522 ms
273,500 KB
testcase_12 AC 107 ms
77,576 KB
testcase_13 AC 95 ms
76,776 KB
testcase_14 AC 2,544 ms
276,608 KB
testcase_15 AC 2,494 ms
273,932 KB
testcase_16 AC 656 ms
106,308 KB
testcase_17 AC 277 ms
81,824 KB
testcase_18 AC 1,702 ms
235,076 KB
testcase_19 AC 1,972 ms
270,928 KB
testcase_20 AC 222 ms
80,308 KB
testcase_21 AC 88 ms
76,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
MOD = 10**9+7
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for _ in range(n):
    ndp = [[0]*(n+1) for _ in range(n+1)]
    for a in range(n+1):
        for b in range(a+1):
            x = dp[a][b]
            if x==0: continue
            ndp[a][b] += x*(a*a-(a-b))
            ndp[a][b] %= MOD
            if b+1 <= n:
                ndp[a][b+1] += x*(a-b)
                ndp[a][b+1] %= MOD
            if a+1 <= n:
                ndp[a+1][b] += x*2*a
                ndp[a+1][b] %= MOD
            if a+1 <= n and b+1 <= n:
                ndp[a+1][b+1] += x
                ndp[a+1][b+1] %= MOD
            if a+2 <= n:
                ndp[a+2][b] += x
                ndp[a+2][b] %= MOD
    dp = ndp

ans = 0
for i in range(n+1):
    ans += dp[i][i]
print(ans%MOD)
0