Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 3698 | Accepted: 1517 |
Description
Farmer John wants to know how much damage another earthquake could do. He wants to know the minimum number of roads whose destruction would isolate a subtree of exactly P (1 <= P <= N) barns from the rest of the barns.
Input
* Lines 2..N: N-1 lines, each with two integers I and J. Node I is node J's parent in the tree of roads.
Output
Sample Input
11 6 1 2 1 3 1 4 1 5 2 6 2 7 2 8 4 9 4 10 4 11
Sample Output
2
這題是我的第二個樹狀DP,還是看着一個大牛的代碼寫的。還是要更加努力呀,努力 加油。。。。。。
每個節點都有兩種不同的狀態:
1.該點被包含在剩下的樹,其子樹則不被包含
2.該點不被包含在剩下的樹,其子樹判斷和該點一樣。
dp[i,j]表示節點i爲根節點得到剩下j個節點的樹所刪邊的最小數目