POJ 1947 Rebuilding Roads
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 8188 | Accepted: 3659 |
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
4 11
Sample Output
2
Hint
Source
现在设dp[j]表示以i为根的子树中节点个数为j的最少删除边数
状态转移方程: dp[1] = tot (tot为他的子节点个数)
dp[j] = min(dp[j],dp[k]-1+dp[s][j-k]) (1<=i<=n,2<=j<=sum(节点总和),1<=k<j,s为i子节点)(i中已有k个节点并从s中选择j-k个,算最少删除边数,s选上所以i->s的边不需删除,所以-1)
#include <iostream>
#include <cstdio> #include <cstring> #include <vector> using namespace std; const int INF=0x3f3f3f3f; int dp[200][200],sum[200],N,P; void Tree_DP(int s) int main() |
* This source code was highlighted by YcdoiT. ( style: Codeblocks )
POJ 1947 Rebuilding Roads的更多相关文章
- [poj 1947] Rebuilding Roads 树形DP
Rebuilding Roads Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10653 Accepted: 4884 Des ...
- POJ 1947 Rebuilding Roads 树形DP
Rebuilding Roads Description The cows have reconstructed Farmer John's farm, with its N barns (1 & ...
- POJ 1947 Rebuilding Roads 树形dp 难度:2
Rebuilding Roads Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 9105 Accepted: 4122 ...
- DP Intro - poj 1947 Rebuilding Roads(树形DP)
版权声明:本文为博主原创文章,未经博主允许不得转载. Rebuilding Roads Time Limit: 1000MS Memory Limit: 30000K Total Submissi ...
- POJ 1947 Rebuilding Roads (树dp + 背包思想)
题目链接:http://poj.org/problem?id=1947 一共有n个节点,要求减去最少的边,行号剩下p个节点.问你去掉的最少边数. dp[u][j]表示u为子树根,且得到j个节点最少减去 ...
- 树形dp(poj 1947 Rebuilding Roads )
题意: 有n个点组成一棵树,问至少要删除多少条边才能获得一棵有p个结点的子树? 思路: 设dp[i][k]为以i为根,生成节点数为k的子树,所需剪掉的边数. dp[i][1] = total(i.so ...
- POJ 1947 Rebuilding Roads(树形DP)
题目链接 题意 : 给你一棵树,问你至少断掉几条边能够得到有p个点的子树. 思路 : dp[i][j]代表的是以i为根的子树有j个节点.dp[u][i] = dp[u][j]+dp[son][i-j] ...
- POJ 1947 - Rebuilding Roads 树型DP(泛化背包转移)..
dp[x][y]表示以x为根的子树要变成有y个点..最少需要减去的边树... 最终ans=max(dp[i][P]+t) < i=(1,n) , t = i是否为整棵树的根 > 更新的时 ...
- DP Intro - poj 1947 Rebuilding Roads
算法: dp[i][j]表示以i为根的子树要变成有j个节点的状态需要减掉的边数. 考虑状态转移的时候不考虑i的父亲节点,就当不存在.最后统计最少减去边数的 时候+1. 考虑一个节点时,有两种选择,要么 ...
随机推荐
- android 事件传递机制 心得
看了网上很多资料. 最后我发现可以用很简单的几句话就能把它说清楚 1 每个 viewgroup 内都有 三个方法 a dispatchTouchEvent 是自己决定要不要(管他爹)要这个苹果的 一般 ...
- list去除并且把值相加
package list; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import ja ...
- 伪集群zookeeper模式下codis的部署安装
1,zookeeper伪集群部署 部署在192.168.0.210服务器上 下载 去官网将3.4.6版本的zookeeper下载下来到/app目录下解压 首先 ...
- 用DOS命令配置服务开机自启动
2016-08-19 15:01 Create 使用命令 sc config 参考博客:http://blog.csdn.net/it1988888/article/details/7992626 ...
- 逐行读取txt文件
header("Content-type:text/html; charset=utf-8"); $handle = fopen('test.php', 'r') or die(' ...
- boolean 和 Boolean 类型数据的差别
工作中遇到页面传递布尔类型的数据问题,需要在代码中判断不能为null,就此思考一下,boolean和Boolean之间的区别?boolean是基本数据类型Boolean是它的封装类,和其他类一样,有属 ...
- cmd chcp命令切换字符格式UTF8
cmd chcp命令切换字符格式 命令介绍: chcp 65001 #换成utf-8代码页 chcp 936 #换成默认的gbk chcp 437 #美国英 ...
- Yoshua Bengio 2016年5月11日在Twitter Boston的演讲PPT
Yoshua Bengio最新演讲:Attention 让深度学习取得巨大成功(46ppt) Yoshua Bengio,电脑科学家,毕业于麦吉尔大学,在MIT和AT&T贝尔实验室做过博士后研 ...
- 数字图像处理- 3.4 空间滤波 and 3.5 平滑空间滤波器
3.4 空间滤波基础 • Images are often corrupted by random variations in intensity, illumination, or have poo ...
- jQM基本代码
<div data-role="page"> <div data-role="header" data-position="fixe ...