結果

問題 No.196 典型DP (1)
ユーザー 👑 rin204rin204
提出日時 2022-10-01 23:31:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 660 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 86,268 KB
実行使用メモリ 89,916 KB
最終ジャッジ日時 2023-08-25 19:59:52
合計ジャッジ時間 7,304 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
70,820 KB
testcase_01 AC 73 ms
71,148 KB
testcase_02 AC 71 ms
70,852 KB
testcase_03 AC 71 ms
70,952 KB
testcase_04 AC 74 ms
70,884 KB
testcase_05 AC 71 ms
71,152 KB
testcase_06 AC 71 ms
70,884 KB
testcase_07 AC 71 ms
70,880 KB
testcase_08 AC 71 ms
70,880 KB
testcase_09 AC 71 ms
70,928 KB
testcase_10 AC 71 ms
70,884 KB
testcase_11 AC 73 ms
70,800 KB
testcase_12 AC 76 ms
75,328 KB
testcase_13 AC 78 ms
75,188 KB
testcase_14 AC 78 ms
75,288 KB
testcase_15 AC 83 ms
75,424 KB
testcase_16 AC 93 ms
75,940 KB
testcase_17 AC 109 ms
76,552 KB
testcase_18 AC 115 ms
77,028 KB
testcase_19 AC 121 ms
77,396 KB
testcase_20 AC 125 ms
77,304 KB
testcase_21 AC 161 ms
77,620 KB
testcase_22 AC 121 ms
77,072 KB
testcase_23 AC 136 ms
79,872 KB
testcase_24 AC 140 ms
85,072 KB
testcase_25 AC 131 ms
78,876 KB
testcase_26 AC 143 ms
89,916 KB
testcase_27 AC 139 ms
89,700 KB
testcase_28 AC 140 ms
89,804 KB
testcase_29 AC 140 ms
89,856 KB
testcase_30 AC 141 ms
89,840 KB
testcase_31 AC 170 ms
77,536 KB
testcase_32 AC 167 ms
77,076 KB
testcase_33 AC 167 ms
77,112 KB
testcase_34 AC 167 ms
77,060 KB
testcase_35 AC 166 ms
77,096 KB
testcase_36 AC 165 ms
77,560 KB
testcase_37 AC 164 ms
77,548 KB
testcase_38 AC 167 ms
77,764 KB
testcase_39 AC 161 ms
77,688 KB
testcase_40 AC 168 ms
77,316 KB
testcase_41 AC 70 ms
70,956 KB
testcase_42 AC 71 ms
70,792 KB
testcase_43 AC 69 ms
70,952 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]
    size = 1
    for npos in edges[pos]:
        if npos == bpos:
            continue
        tmp, s = dfs(npos, pos)
        size += s
        ndp = [0] * size
        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, size

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