樹形dp - Codeforces Round #322 (Div. 2) F Zublicanes and Mumocrates
Zublicanes and Mumocrates
Problem's Link
Mean:
給定一個無向圖,需要把這個圖分成兩部分,使得兩部分中邊數為1的結點數量相等,最少需要去掉多少條邊.
analyse:
樹形dp.
dp[cur][i][j]:當cur為i集合的時候 有j個和i同集合的方案
狀態轉移方程為:
dp[cur][i][j+k] = min{dp[to][i^1][j=(葉子個數-d)]+dp[cur][i][k]+1,dp[to][i][j]+dp[cur][i][k]}
cnt為葉子節點的個數.
最後答案是:min{ dp[root][0][cnt/2] ,dp[root][1][cnt/2]}
Time complexity: O(N)
相關文章
- Codeforces Round #358 (Div. 2) D dp
- Codeforces Round #316 (Div. 2) E dp
- Codeforces Round #321 (Div. 2) D 狀壓dp
- Codeforces Round 970 (Div. 3)A~F
- Codeforces Round #336 (Div. 2) D 區間dp
- Codeforces Round #336 (Div. 2) C 二分+dp
- Codeforces Round #214 (Div. 2)(揹包變形)
- Codeforces Round #360 (Div. 2) E dp 類似01揹包
- Educational Codeforces Round 167 (Rated for Div. 2) D(dp,貪心)
- Codeforces Round 987 (Div. 2) (C~F) 題解/個人記錄
- Codeforces Round #639 (Div. 2)
- Codeforces Round #541 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #448 (Div. 2) A
- Codeforces Round #217 (Div. 2)
- Codeforces Round #256 (Div. 2)
- Codeforces Round #259 (Div. 2)
- Codeforces Round #257 (Div. 2)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #171 (Div. 2)
- Codeforces Round #173 (Div. 2)
- Codeforces Round 951 (Div. 2)
- Codeforces Round 955 (Div. 2)
- Codeforces Round 953 (Div. 2)
- Codeforces Round 975 (Div. 2)
- Codeforces Round 976 (Div. 2)
- Codeforces Round 972 (Div. 2)
- Codeforces Round 979 (Div. 2)
- Codeforces Round 982 (Div. 2)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 934 (Div. 2)
- Codeforces Round 940 (Div. 2)
- Codeforces Round 973 (Div. 2)
- Codeforces Round 960 (Div. 2)