結果

問題 No.196 典型DP (1)
ユーザー roarisroaris
提出日時 2020-11-24 04:35:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 91,364 KB
最終ジャッジ日時 2023-10-01 00:46:57
合計ジャッジ時間 6,829 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,020 KB
testcase_01 AC 75 ms
71,096 KB
testcase_02 AC 77 ms
70,896 KB
testcase_03 AC 74 ms
71,176 KB
testcase_04 AC 73 ms
71,240 KB
testcase_05 AC 72 ms
71,232 KB
testcase_06 AC 73 ms
70,892 KB
testcase_07 AC 74 ms
70,896 KB
testcase_08 AC 73 ms
71,016 KB
testcase_09 AC 71 ms
71,156 KB
testcase_10 AC 73 ms
71,172 KB
testcase_11 AC 74 ms
71,304 KB
testcase_12 AC 79 ms
75,268 KB
testcase_13 AC 81 ms
75,940 KB
testcase_14 AC 83 ms
76,156 KB
testcase_15 AC 83 ms
76,024 KB
testcase_16 AC 92 ms
76,192 KB
testcase_17 AC 106 ms
77,392 KB
testcase_18 AC 105 ms
76,628 KB
testcase_19 AC 115 ms
77,760 KB
testcase_20 AC 120 ms
77,836 KB
testcase_21 AC 143 ms
77,980 KB
testcase_22 AC 117 ms
77,700 KB
testcase_23 AC 129 ms
81,548 KB
testcase_24 AC 130 ms
83,704 KB
testcase_25 AC 122 ms
78,036 KB
testcase_26 AC 132 ms
91,364 KB
testcase_27 AC 133 ms
90,468 KB
testcase_28 AC 134 ms
91,040 KB
testcase_29 AC 132 ms
90,840 KB
testcase_30 AC 129 ms
90,884 KB
testcase_31 AC 151 ms
77,516 KB
testcase_32 AC 149 ms
77,124 KB
testcase_33 AC 149 ms
77,424 KB
testcase_34 AC 150 ms
77,268 KB
testcase_35 AC 148 ms
77,392 KB
testcase_36 AC 149 ms
77,576 KB
testcase_37 AC 151 ms
78,656 KB
testcase_38 AC 150 ms
77,568 KB
testcase_39 AC 142 ms
77,540 KB
testcase_40 AC 149 ms
77,696 KB
testcase_41 AC 74 ms
71,176 KB
testcase_42 AC 75 ms
71,100 KB
testcase_43 AC 72 ms
70,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2010)

def dfs(v, pv):
    dp = [1]
    
    for nv in G[v]:
        if nv==pv:
            continue
        
        ndp = dfs(nv, v)
        merge = [0]*(len(dp)+len(ndp)-1)
        
        for i in range(len(dp)):
            for j in range(len(ndp)):
                merge[i+j] = (merge[i+j]+dp[i]*ndp[j])%MOD
        
        dp = merge
        
    dp.append(dp[-1])
    return dp

N, K = map(int, input().split())
G = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)

MOD = 10**9+7
print(dfs(0, -1)[K])
0