結果

問題 No.196 典型DP (1)
ユーザー ayaoniayaoni
提出日時 2021-06-27 19:38:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 95,172 KB
最終ジャッジ日時 2023-09-07 18:08:27
合計ジャッジ時間 7,119 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,336 KB
testcase_01 AC 73 ms
71,068 KB
testcase_02 AC 73 ms
71,256 KB
testcase_03 AC 74 ms
71,256 KB
testcase_04 AC 78 ms
71,272 KB
testcase_05 AC 74 ms
71,468 KB
testcase_06 AC 75 ms
71,260 KB
testcase_07 AC 74 ms
71,536 KB
testcase_08 AC 73 ms
71,336 KB
testcase_09 AC 74 ms
71,268 KB
testcase_10 AC 73 ms
71,376 KB
testcase_11 AC 79 ms
75,808 KB
testcase_12 AC 79 ms
75,816 KB
testcase_13 AC 85 ms
76,128 KB
testcase_14 AC 82 ms
76,416 KB
testcase_15 AC 91 ms
76,452 KB
testcase_16 AC 88 ms
76,472 KB
testcase_17 AC 104 ms
76,872 KB
testcase_18 AC 106 ms
78,020 KB
testcase_19 AC 119 ms
78,116 KB
testcase_20 AC 118 ms
77,948 KB
testcase_21 AC 127 ms
78,212 KB
testcase_22 AC 117 ms
78,252 KB
testcase_23 AC 141 ms
87,496 KB
testcase_24 AC 135 ms
87,144 KB
testcase_25 AC 138 ms
86,464 KB
testcase_26 AC 169 ms
95,036 KB
testcase_27 AC 165 ms
94,548 KB
testcase_28 AC 167 ms
94,268 KB
testcase_29 AC 170 ms
95,172 KB
testcase_30 AC 166 ms
94,992 KB
testcase_31 AC 154 ms
77,628 KB
testcase_32 AC 154 ms
77,632 KB
testcase_33 AC 155 ms
77,632 KB
testcase_34 AC 156 ms
77,780 KB
testcase_35 AC 152 ms
77,616 KB
testcase_36 AC 162 ms
77,956 KB
testcase_37 AC 121 ms
77,988 KB
testcase_38 AC 152 ms
77,808 KB
testcase_39 AC 148 ms
77,724 KB
testcase_40 AC 156 ms
77,952 KB
testcase_41 AC 72 ms
71,256 KB
testcase_42 AC 72 ms
71,256 KB
testcase_43 AC 71 ms
71,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N,K = MI()
Graph = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = MI()
    Graph[a].append(b)
    Graph[b].append(a)
mod = 10**9+7


def DP(u,par):
    dp = [1,1]  # dp[i] = 頂点uを根とする部分木において、丁度i個の頂点が黒に塗られている様な塗り方
    for v in Graph[u]:
        if v == par:
            continue
        dp_v = DP(v,u)
        a = len(dp)
        b = len(dp_v)
        new_dp = [0]*(a+b-1)
        for i in range(a):
            for j in range(b):
                if i != a-1:
                    new_dp[i+j] += dp[i]*dp_v[j]
                    new_dp[i+j] %= mod
        new_dp[-1] = 1
        dp = new_dp
    return dp


ans = DP(0,-1)[K]
print(ans)
0