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. 考虑一个节点时,有两种选择,要么 ...
随机推荐
- [iOS 图像处理相关]
//使用CGImage获取并修改图片像素 #define Mask8(x) ( (x) & 0xFF ) #define R(x) ( Mask8(x) ) #define G(x) ( Ma ...
- [Xcode 自带svn的使用]
xcode自带svn的使用 1.代码中 某文件后面有 “M” 标记,表示该文件已被修改,需要commit. (右键该文件 -> source control -> c ...
- 【Alpha版本】 第七天 11.15
一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 完成我要招聘的招聘详情显示,完成简历填写及显示功能 完成我要应聘的 ...
- mybatis报错Mapped Statements collection does not contain value for com.inter.IOper
首页 > 精品文库 > mybatis报错Mapped Statements collection does not contain value for com.inter.IOper m ...
- 64位centos下安装python的PIL模块
http://blog.csdn.net/xiaojun1288/article/details/8673529
- 机器学习笔记—Logistic回归
本文申明:本系列笔记全部为原创内容,如有转载请申明原地址出处.谢谢 序言:what is logistic regression? Logistics 一词表示adj.逻辑的;[军]后勤学的n.[逻] ...
- 转:遗传算法解决TSP问题
1.编码 这篇文章中遗传算法对TSP问题的解空间编码是十进制编码.如果有十个城市,编码可以如下: 0 1 2 3 4 5 6 7 8 9 这条编码代表着一条路径,先经过0,再经过1,依次下去. 2.选 ...
- angularjs中ng-change使用方法
ng-change需与ng-model结合使用,官网说明如下:Note, this directive requires ngModel to be present. <label for=&q ...
- CentOS7安装mysql5
CentOS7的yum源中默认没有mysql. 1. 下载mysql的repo源 $ wget http://repo.mysql.com/mysql-community-release-el7-5. ...
- easyui tree获取直接子节点而不获取孙子节点方法
$(node.target.nextElementSibling).children().each(function(index,ele){ if(checked){ $('#rcDimTreeRow ...