結果

問題 No.196 典型DP (1)
ユーザー roarisroaris
提出日時 2020-11-24 04:34:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 86,716 KB
実行使用メモリ 92,708 KB
最終ジャッジ日時 2023-10-01 00:46:50
合計ジャッジ時間 7,461 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,012 KB
testcase_01 AC 75 ms
70,896 KB
testcase_02 AC 72 ms
71,144 KB
testcase_03 AC 72 ms
71,008 KB
testcase_04 AC 71 ms
71,264 KB
testcase_05 AC 72 ms
71,000 KB
testcase_06 AC 73 ms
71,336 KB
testcase_07 AC 73 ms
70,908 KB
testcase_08 AC 73 ms
71,212 KB
testcase_09 AC 73 ms
70,988 KB
testcase_10 AC 71 ms
71,260 KB
testcase_11 AC 74 ms
71,216 KB
testcase_12 AC 81 ms
75,240 KB
testcase_13 AC 83 ms
75,932 KB
testcase_14 AC 80 ms
75,928 KB
testcase_15 AC 86 ms
75,996 KB
testcase_16 AC 90 ms
76,136 KB
testcase_17 AC 110 ms
77,496 KB
testcase_18 AC 106 ms
76,344 KB
testcase_19 AC 109 ms
77,984 KB
testcase_20 AC 116 ms
77,780 KB
testcase_21 AC 141 ms
77,932 KB
testcase_22 AC 115 ms
77,752 KB
testcase_23 AC 126 ms
81,776 KB
testcase_24 AC 125 ms
83,700 KB
testcase_25 AC 117 ms
78,212 KB
testcase_26 AC 131 ms
91,100 KB
testcase_27 AC 129 ms
90,480 KB
testcase_28 AC 127 ms
91,048 KB
testcase_29 AC 133 ms
91,124 KB
testcase_30 AC 130 ms
92,708 KB
testcase_31 AC 147 ms
77,448 KB
testcase_32 AC 147 ms
77,420 KB
testcase_33 AC 146 ms
77,360 KB
testcase_34 AC 148 ms
77,408 KB
testcase_35 AC 145 ms
77,308 KB
testcase_36 AC 146 ms
77,516 KB
testcase_37 AC 149 ms
78,504 KB
testcase_38 AC 146 ms
77,560 KB
testcase_39 AC 143 ms
77,496 KB
testcase_40 AC 149 ms
77,656 KB
testcase_41 AC 73 ms
71,216 KB
testcase_42 AC 74 ms
71,088 KB
testcase_43 AC 73 ms
71,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def dfs(v, pv):
    global ans
    
    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