結果

問題 No.196 典型DP (1)
ユーザー dddggdddgg
提出日時 2024-01-19 15:51:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 525 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 89,628 KB
最終ジャッジ日時 2024-01-19 15:51:53
合計ジャッジ時間 5,822 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,460 KB
testcase_01 AC 33 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 32 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 33 ms
53,460 KB
testcase_07 AC 32 ms
53,460 KB
testcase_08 AC 32 ms
53,460 KB
testcase_09 AC 33 ms
53,460 KB
testcase_10 AC 34 ms
53,460 KB
testcase_11 AC 34 ms
53,460 KB
testcase_12 AC 42 ms
59,320 KB
testcase_13 AC 38 ms
59,580 KB
testcase_14 AC 40 ms
61,848 KB
testcase_15 AC 58 ms
61,696 KB
testcase_16 AC 61 ms
68,288 KB
testcase_17 AC 73 ms
75,464 KB
testcase_18 AC 80 ms
76,056 KB
testcase_19 AC 82 ms
76,452 KB
testcase_20 AC 100 ms
76,180 KB
testcase_21 AC 118 ms
76,320 KB
testcase_22 AC 86 ms
76,068 KB
testcase_23 AC 98 ms
77,876 KB
testcase_24 AC 91 ms
77,968 KB
testcase_25 AC 95 ms
76,976 KB
testcase_26 AC 110 ms
89,376 KB
testcase_27 AC 103 ms
89,372 KB
testcase_28 AC 97 ms
89,628 KB
testcase_29 AC 101 ms
89,380 KB
testcase_30 AC 114 ms
89,380 KB
testcase_31 AC 118 ms
76,184 KB
testcase_32 AC 119 ms
76,184 KB
testcase_33 AC 122 ms
76,184 KB
testcase_34 AC 124 ms
76,184 KB
testcase_35 AC 122 ms
76,184 KB
testcase_36 AC 127 ms
76,452 KB
testcase_37 AC 121 ms
76,328 KB
testcase_38 AC 125 ms
76,304 KB
testcase_39 AC 134 ms
76,308 KB
testcase_40 AC 141 ms
76,312 KB
testcase_41 AC 33 ms
53,460 KB
testcase_42 AC 33 ms
53,460 KB
testcase_43 AC 32 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

n, k = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v = map(int, input().split())
    edges[u].append(v)
    edges[v].append(u)

def dfs(pos, bpos):
    dp = [1]
    for npos in edges[pos]:
        if npos == bpos:
            continue
        tmp= dfs(npos, pos)
        ndp = [0] * (len(dp)+len(tmp)-1)
        for i, v in enumerate(dp):
            for j, u in enumerate(tmp):
                ndp[i + j] += u * v
                ndp[i + j] %= MOD
        dp = ndp
    dp.append(1)
    return dp

dp= dfs(0, -1)
print(dp[k])
0