結果

問題 No.140 みんなで旅行
ユーザー convexineqconvexineq
提出日時 2021-02-14 03:00:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,132 ms / 5,000 ms
コード長 904 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 81,848 KB
最終ジャッジ日時 2023-09-28 12:36:47
合計ジャッジ時間 17,766 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,184 KB
testcase_01 AC 75 ms
71,128 KB
testcase_02 AC 129 ms
76,608 KB
testcase_03 AC 76 ms
71,356 KB
testcase_04 AC 75 ms
71,328 KB
testcase_05 AC 73 ms
71,032 KB
testcase_06 AC 74 ms
71,108 KB
testcase_07 AC 75 ms
71,304 KB
testcase_08 AC 76 ms
71,248 KB
testcase_09 AC 76 ms
71,140 KB
testcase_10 AC 81 ms
76,364 KB
testcase_11 AC 3,106 ms
81,768 KB
testcase_12 AC 115 ms
76,468 KB
testcase_13 AC 98 ms
76,532 KB
testcase_14 AC 3,132 ms
81,776 KB
testcase_15 AC 3,077 ms
81,848 KB
testcase_16 AC 799 ms
78,968 KB
testcase_17 AC 329 ms
78,160 KB
testcase_18 AC 2,103 ms
81,056 KB
testcase_19 AC 2,452 ms
81,320 KB
testcase_20 AC 263 ms
77,748 KB
testcase_21 AC 94 ms
76,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def clear():
    for i in range(n+1):
        for j in range(n+1):
            ndp[i][j] = 0
n = int(input())
MOD = 10**9+7
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
ndp = [[0]*(n+1) for _ in range(n+1)]
for _ in range(n):
    clear()
    for a in range(n+1):
        for b in range(n+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 = ndp,dp

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