ACM: 动态规划题 poj 1947
来源:互联网 发布:金山tw域名遭抢注 编辑:程序博客网 时间:2024/06/16 09:10
Farmer John wants to know how much damage another earthquake coulddo. He wants to know the minimum number of roads whose destructionwould 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 isnode 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
题意: 在一棵树结构上, 要求断开最少的边可以得到节点个数为P的子树.
解题思路:
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define MAX 155
const int INF = (1<<29);
int n, p, root;
int g[MAX][MAX], num[MAX], flag[MAX];
int dp[MAX][MAX];
inline int min(int a, int b)
{
}
void dfs(int u)
{
}
int main()
{
//
}
- ACM: 动态规划题 poj 1947
- ACM: 简单动态规划题 poj 2955
- ACM: 动态规划题 poj 2241
- ACM: 动态规划题 poj 1054
- ACM: 动态规划题 poj 2948
- ACM: 动态规划题 poj 1925
- ACM: 动态规划题 poj 3034
- ACM: 动态规划题 poj 2411
- ACM: 动态规划题 poj 2486
- ACM: 动态规划题 poj 3140
- ACM: 动态规划题 poj 3659
- ACM: 动态规划题 poj 2923
- ACM: dp动态规划题(难) poj 3267 …
- ACM: dp题(动态规划) poj 2151 (d…
- ACM: 树状DP 动态规划题 poj 1463 …
- ACM: 动态规划题 poj 2057 树状DP
- ACM:动态规划题 poj 1015
- ACM: 动态规划题 poj&nb…
- 埃拉托斯特尼筛法求素数
- 兴趣学习: 摆脱“三天打渔两天晒网”…
- ACM: 动态规划题 poj 1185 想了两…
- windows.h
- ACM: 动态规划题 poj 2057 树状DP
- ACM: 动态规划题 poj 1947
- ACM: 动态规划题 poj 2486
- ACM: 动态规划题 poj 3140
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 1192 树形DP
- ACM: 动态规划题 poj 3659
- 动态规划: 经典0-1背包问题 (转)
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 3211 背包变…