hdu 1011 Starship Troopers(树上背包)
Problem Description
To kill all the bugs is always easier than to capture their brains. A map is drawn for you, with all the rooms marked by the amount of bugs inside, and the possibility of containing a brain. The cavern's structure is like a tree in such a way that there is one unique path leading to each room from the entrance. To finish the battle as soon as possible, you do not want to wait for the troopers to clear a room before advancing to the next one, instead you have to leave some troopers at each room passed to fight all the bugs inside. The troopers never re-enter a room where they have visited before.
A starship trooper can fight against 20 bugs. Since you do not have enough troopers, you can only take some of the rooms and let the nerve gas do the rest of the job. At the mean time, you should maximize the possibility of capturing a brain. To simplify the problem, just maximize the sum of all the possibilities of containing brains for the taken rooms. Making such a plan is a difficult job. You need the help of a computer.
Input
The last test case is followed by two -1's.
Output
Sample Input
Sample Output
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
using namespace std;
typedef long long ll;
const double inf=1e20;
const int maxn=+;
const int maxm=+; vector<ll>edges[maxn]; ll f[maxn][maxm]; ll n,m;
ll v[maxn],c[maxn]; void addedge(ll u,ll v){
edges[u].push_back(v);
edges[v].push_back(u); } void clear_(ll n){
for(ll i=;i<=n;i++)edges[i].clear();
memset(f,,sizeof(f));
} void dp(ll x,ll fa){
for(ll i=;i<(ll)edges[x].size();i++){
ll y=edges[x][i];
if(y!=fa){
dp(y,x);
for(ll t=m;t>=;t--){
for(ll j=t;j>=;j--){
if(t-j>=){
f[x][t]=max(f[x][t],f[x][t-j]+f[y][j]);
}
}
}
}
}
for(ll t=m;t>;t--){
if(t>=c[x])f[x][t]=f[x][t-c[x]]+v[x];
else f[x][t]=;
}
} int main(){
while(scanf("%lld%lld",&n,&m)!=EOF){
if(n==m&&m==-)break;
for(int i=;i<=n;i++){
scanf("%lld%lld",&c[i],&v[i]);
c[i]=(c[i]+)/;
} clear_(n);
for(int i=;i<n;i++){
ll u,v;
scanf("%lld%lld",&u,&v);
addedge(u,v);
}
dp(,);
printf("%lld\n",f[][m]);
}
return ;
}
hdu 1011 Starship Troopers(树上背包)的更多相关文章
- hdu 1011 Starship Troopers(树形背包)
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1011 Starship Troopers 树形背包dp
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1011 Starship Troopers 树形+背包dp
http://acm.hdu.edu.cn/showproblem.php?pid=1011 题意:每个节点有两个值bug和brain,当清扫该节点的所有bug时就得到brain值,只有当父节点被 ...
- HDU 1011 Starship Troopers【树形DP/有依赖的01背包】
You, the leader of Starship Troopers, are sent to destroy a base of the bugs. The base is built unde ...
- HD 1011 Starship Troopers(树上的背包)
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1011 Starship Troopers (树dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1011 题意: 题目大意是有n个房间组成一棵树,你有m个士兵,从1号房间开始让士兵向相邻的房间出发,每个 ...
- [HDU 1011] Starship Troopers
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1011 Starship Troopers(树形DP入门)
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1011(Starship Troopers,树形dp)
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- 为什么用nginx:它的5个主要优点
1.高并发,高性能 2.可扩展性好啊 3.高可靠性 4.热部署 5.BSD许可证
- Javascript小白经典题型(二)
51. 输出的是什么? function getInfo(member, year) { member.name = "Lydia"; year = "1998" ...
- ORB-SLAM2 初体验 —— 配置安装
转载请注明出处,谢谢 原创作者:MingruiYU 原创链接:https://www.cnblogs.com/MingruiYu/p/12286752.html ORB-SLAM2作为目前应用最广泛的 ...
- java10幸运抽奖
public class jh_01_知识点回顾 { public static void main(String[] args) { int a = 10; // 变量.标签. // 重新给a赋值. ...
- 文本相似性热度统计(python版)
0. 写在前面 节后第一篇,疫情还没结束,黎明前的黑暗,中国加油,武汉加油,看了很多报道,发现只有中国人才会帮助中国人,谁说中国人一盘散沙?也许是年龄大了,看到全国各地的医务人员源源不断的告别家人去支 ...
- AppBox实战: 如何实现一对多表单的增删改查
本篇通过完整示例介绍如何实现一对多关系表单的相应服务及视图. 一.准备数据结构 示例所采用的数据结构为"物资需求"一对多"物资清单",通过IDE的实体设 ...
- SQLYOG导入数据时报错,出现找不到Microsoft office 元驱动程式,并且无法安装64位office Access驱动
当我们使用mysql导入外部数据时(如Excel表),有时会出现如下的错误问题,即找不到64位access驱动.为了解决这个问题,我们需要下载相应的驱动,通过下图中的点击此链接即可进入下载页面(htt ...
- Unity酱~ 卡通渲染技术分析(二)
前面的话 上一篇Unity酱~ 卡通渲染技术分析(一) 写了CharaMain.cginc,服装的渲染是怎么实现的.这篇来分析一下头发跟皮肤的实现 头发 本来以为unitychan的头发会有各向异性的 ...
- 全网最全小白搭建Hexo+Gitee/Coding
全网最全小白搭建Hexo+Gitee/Coding 本站内容已全部转移到https://www.myyuns.ltd,具体请移步到www.myyuns.ltd查看
- 学习CSS之用CSS实现时钟效果
一.机械时钟 1.最终效果 用 CSS 绘制的机械时钟效果如下: HTML 中代码结构为: <body> <div class="clock"> ...