結果

問題 No.196 典型DP (1)
ユーザー neterukunneterukun
提出日時 2019-06-15 16:47:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 1,203 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 134,016 KB
最終ジャッジ日時 2024-04-29 19:14:30
合計ジャッジ時間 8,814 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,968 KB
testcase_01 AC 41 ms
51,840 KB
testcase_02 AC 41 ms
52,352 KB
testcase_03 AC 41 ms
52,352 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 43 ms
51,840 KB
testcase_08 AC 44 ms
51,840 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 42 ms
51,968 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 121 ms
102,272 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 499 ms
127,104 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 495 ms
127,104 KB
testcase_36 AC 472 ms
134,016 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 42 ms
51,840 KB
testcase_42 AC 42 ms
51,968 KB
testcase_43 AC 42 ms
51,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n-1)]

tree = [[] for i in range(n)]
for i in range(n-1):
    tree[info[i][0]].append(info[i][1])

dp = [[0]*(n+1) for i in range(n)]

#すべて白色で塗る通り数は、それぞれの部分木に対して1通り
for i in range(n):
    dp[i][0] = 1

    
def dfs(pos):
    cnt = 1
    #部分木が葉のとき
    if not tree[pos]:
        dp[pos][cnt] = 1
        return cnt #cnt = 1

    for child_pos in tree[pos]:
        cnt_child = dfs(child_pos)
        tmp = [0]*(n+1)
        for i in range(cnt+1):
            for j in range(cnt_child+1):
                if i+j >= n+1:
                    break
                tmp[i+j] += dp[pos][i]*dp[child_pos][j]
        cnt += cnt_child
        for i in range(cnt+1):
            dp[pos][i] = tmp[i]

    dp[pos][cnt] = 1 
    return cnt
dfs(0)
print(dp[0][k])
      
0