hdu 3586 二分+树形dp

Information Disturbing

Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1335 Accepted Submission(s): 489

Problem Description In the battlefield , an effective way to defeat enemies is to break their communication system.
The information department told you that there are n enemy soldiers and their network which have n-1 communication routes can cover all of their soldiers. Information can exchange between any two soldiers by the communication routes. The number 1 soldier is the total commander and other soldiers who have only one neighbour is the frontline soldier.
Your boss zzn ordered you to cut off some routes to make any frontline soldiers in the network cannot reflect the information they collect from the battlefield to the total commander( number 1 soldier).
There is a kind of device who can choose some routes to cut off . But the cost (w) of any route you choose to cut off can’t be more than the device’s upper limit power. And the sum of the cost can’t be more than the device’s life m.
Now please minimize the upper limit power of your device to finish your task.

Input The input consists of several test cases.
The first line of each test case contains 2 integers: n(n Each of the following N-1 lines is of the form:
ai bi wi
It means there’s one route from ai to bi(undirected) and it takes wi cost to cut off the route with the device.
(1 The input ends with n=m=0.

Output Each case should output one integer, the minimal possible upper limit power of your device to finish your task.
If there is no way to finish the task, output -1.
Sample Input

5 5 1 3 2 1 4 3 3 5 5 4 2 6 0 0

Sample Output

3

题意:切断一定的边,使得所有叶子节点与根节点断开,限制条件是断开的边权之和小于某一值,且每一条边权小于某一值x,求x的最小值。

一看题就知道是二分+树形dp判断可行性, INF上界不能太大,否则会溢出,因为这个wa好多次。

代码:

/* *********************************************** Author :xianxingwuguan Created Time :2014-2-6 16:15:10 File Name :1.cpp ************************************************ */ #pragma comment(linker, "/STACK:102400000,102400000") #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF 1000000 #define eps 1e-8 #define pi acos(-1.0) typedef long long ll; const int maxn=4009; int head[maxn],tol; struct node{ int next,to,val; node(){}; node(int _next,int _to,int _val):next(_next),to(_to),val(_val){} }edge[5*maxn]; void add(int u,int v,int val){ edge[tol]=node(head[u],v,val); head[u]=tol++; } int dfs(int u,int fa,int num){ int sum=0,flag=0; for(int i=head[u];i!=-1;i=edge[i].next){ int v=edge[i].to; if(v==fa)continue; int tt=dfs(v,u,num); if(tt>edge[i].val&&edge[i].val>1; if(dfs(1,1,mid)

点击复制链接 与好友分享!回本站首页
您对本文章有什么意见或着疑问吗?请到论坛讨论您的关注和建议是我们前行的参考和动力
上一篇:hdu 4336 Card Collector (概率dp)
下一篇:题目1184:二叉树遍历
相关文章

Max Sum &&http://acm.hdu.edu.cn/s

hdu 1003 Max Sum

HDU 4007

hdu1856并查集

HDU2094

hdu 1089 Robotic Sort

hdu 1754

HDU 4028

http://acm.hdu.edu.cn/showproblem.p

HDU 4022

图文推荐
hdu 3586 二分+树形dp
ZOJ 3640 Help Me
hdu 3586 二分+树形dp
CF 518C(Anya and
hdu 3586 二分+树形dp
hdu 1016 Prime R
UVA - 11987 - A

分类:默认分类 时间:2012-01-03 人气:7
本文关键词:
分享到:

相关文章

  • hdu 4336 Card Collector (概率dp) 2014-06-05

    题目大意: 收集卡片,问收集齐n张卡片需要买多少包方便面的期望- -虽然不是方便面。 解题思路: 用1表示该位的卡片已经有,0表示没有。 dp[s] 表示拥有了s状态下1的卡片,还要买多少包才能凑齐n张卡片的期望。 所以 ,当你及其了所有的卡片。即 dp[(1 下面再来分析状态转移。 假设我们要收集齐 6 张,可是现在我们收集齐了五张。 那么你要中第六张。 就是第六包要中1 或2 或3 ...或6... 所以要枚举所有 五包的情况,然后因为任一种情况都是互不影响的,所以是相加。 #include

  • hdu 1693 Eat the Trees (插头dp入门) 2012-01-01

    Eat the Trees Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2507 Accepted Submission(s): 1225 Problem Description Most of us know that in the game called DotA(Defense of the Ancient), Pudge is a

  • HDU 2571 命运 2012-01-01

    题意:给出一个矩阵,要求从1,1走到n,m,每个格子里都有一定的幸运值,每次只能向下或向右走,如果当前格子是(x,y),下一步可以是(x+1,y),(x,y+1)或者(x,y*k) 其中k>1。 求走到n,m能得到的最大幸运值. 算一道简单的dp题吧. 设dp[i][j]为走到i,j位置能得到的最大值. 那么dp[i][j]=max(dp[i][j - 1], dp[i - 1][j], max{dp[i][k] k满足 k | j 也就是整除j}). 初始化dp为负无穷. dp[1][1

  • hdu 4975 最大流及其唯一性判定(有向图环判断算法升级) 2012-01-02

    就当时最大流再次复习吧。。动手敲一下。。。经典解法不想说了。。这题主要是坑时间,10个提交7个tle。 环的判断,曾经用简单dfs方法,这次的就tle了!别人说要用很?诺?inic,我感觉自己dinic不可能超时,坚信是判断环慢了,于是学习了新断环的方法:删除点/边!从某点进去,若该点的所有边都遍历过还是无功而返,那么该店以后不用再进入了(这么简单的道感觉自己应该要想到啊!愚蠢啊!)开始时用只删除边,还是tle!nb!于是自己删点又删边,一下到156ms,前5了! #include #inclu

  • hdu 3306 Another kind of Fibonacci 2012-01-03

    Another kind of Fibonacci Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1526 Accepted Submission(s): 583 Problem Description As we all known , the Fibonacci series : F(0) = 1, F(1) = 1, F(N) = F

  • HDU 3949 XOR(高斯消元搞基) 2012-01-04

    HDU 3949 XOR 题目链接 题意:给定一些数字,问任取几个异或值第k大的 思路:高斯消元搞基,然后从低位外高位去推算 代码: #include #include #include using namespace std; typedef long long ll; const int N = 10005; int t, n; ll a[N]; void gauss() { int r = 0; for (int i = 60; i >= 0; i--) { int j; for (

  • HDU 4870 Rating(高斯消元) 2012-01-05

    HDU 4870 Rating 题目链接 题意:一个人注册两个账号,初始rating都是0,他每次拿低分的那个号去打比赛,赢了加50分,输了扣100分,胜率为p,他会打到直到一个号有1000分为止,问比赛场次的期望 思路:f(i, j)表示i >= j,第一个号i分,第二个号j分时候,达到目标的期望,那么可以列出转移为f(i, j) = p f(i', j') + (1 - p) f(i'' + j'') + 1 f(i', j')对应的是赢了加分的状态,f(i'', j'')对应输的扣分

  • hdu 2871 Memory Control(线段树) 2012-01-09

    题目链接:hdu 2871 Memory Control 题目大意:模拟一个内存分配机制。 Reset:重置,释放所有空间 New x:申请内存为x的空间,输出左地址 Free x:释放地址x所在的内存块 Get x:查询第x个内存块,输出左地址 解题思路:一开始全用线段树去做,写的乱七八糟,其实只要用线段树维护可用内存。然后用户一个vector记录所有的内存块。 #include #include #include #include using namespace std; const int

  • hdu 3199 动态规划 2012-01-10

    f[0]=1; 动规方程 f[i]=min(p1*f[x1],p2*f[x2],p3*f[x3]); 这题用long long 竟然WA #include #include using namespace std; __int64 dp[600000]; __int64 Min(__int64 a,__int64 b,__int64 c) { a=min(a,b); return a=min(a,c); } int main() { __int64 i; __int64 p1,p2,p3,n;

Copyright (C) quwantang.com, All Rights Reserved.

趣玩堂 版权所有 京ICP备15002868号

processed in 0.134 (s). 10 q(s)