hdu 1011 Starship Troopers 经典的树形DP ****
Starship Troopers
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8540 Accepted Submission(s): 2379
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.
The last test case is followed by two -1's.
50 10
40 10
40 20
65 30
70 30
1 2
1 3
2 4
2 5
1 1
20 7
-1 -1
next one, instead you have to leave some troopers at each room passed to fight
all the bugs inside.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int n,m;
int w[],val[];
struct node
{
int next[];
int num;
}f[];
int dp[][];
bool use[]; int Max(int x,int y)
{
return x>y? x:y;
} void dfs(int k)
{
int i,j,t,s;
use[k]=true;
int num=(w[k]+)/;
for(i=num;i<=m;i++) dp[k][i]=val[k]; for(i=;i<=f[k].num;i++)
{
t=f[k].next[i];
if(use[t]==true) continue;
dfs(t);
for(j=m;j>=num;j--)
{
for(s=;s<=j;s++)
{
if(dp[k][j-s]!=-)
dp[k][j]=Max(dp[k][j],dp[k][j-s]+dp[t][s]);
}
}
}
} int main()
{
int i,x,y;
while(scanf("%d%d",&n,&m)>)
{
if(n==-&&m==-)break;
memset(dp,-,sizeof(dp));
memset(use,false,sizeof(use)); for(i=;i<=;i++)
f[i].num=; for(i=;i<=n;i++)
scanf("%d%d",&w[i],&val[i]);
for(i=;i<n;i++)
{
scanf("%d%d",&x,&y);
f[x].num++;
f[x].next[f[x].num]=y; f[y].num++;
f[y].next[f[y].num]=x;
}
if(m==)
{
printf("0\n");
continue;
}
dp[][m]=;
/*
1 1
21 1 --> 0
*/
dfs();
printf("%d\n",dp[][m]); }
return ;
}
hdu 1011 Starship Troopers 经典的树形DP ****的更多相关文章
- 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 ...
- 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/Other ...
- hdu 1011(Starship Troopers,树形dp)
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1011 Starship Troopers 树形DP 有坑点
本来是一道很水的树形DP题 设dp[i][j]表示,带着j个人去攻打以节点i为根的子树的最大收益 结果wa了一整晚 原因: 坑点1: 即使这个节点里面没有守卫,你如果想获得这个节点的收益,你还是必须派 ...
- HDU 1011 Starship Troopers星河战队(树形dp)
题意 有n个洞穴编号为1-n,洞穴间有通道,形成了一个n-1条边的树, 洞穴的入口即根节点是1. 每个洞穴有x只bugs,并有价值y的金子,全部消灭完一个洞穴的虫子,就可以获得这个洞穴的y个金子. 现 ...
- hdu 1011 Starship Troopers(树形背包)
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- [HDU 1011] Starship Troopers
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1011 Starship Troopers(树上背包)
Problem Description You, the leader of Starship Troopers, are sent to destroy a base of the bugs. Th ...
随机推荐
- selenium爬取qq空间,requests爬取雪球网数据
一.爬取qq空间好友动态数据 # 爬取qq空间好友状态信息(说说,好友名称),并屏蔽广告 from selenium import webdriver from time import sleep f ...
- Python环境安装与升级
Python是跨平台的,它可以运行在Windows,Mac,Linux/Unix系统上,在Windows上写的Python程序,在Linux上也是能够运行的.目前,Python有两个大版本,一个是2. ...
- 快速上手日期插件laydate
1.laydate 这款插件有独立版的,也有作为layui模块的,两种使用方式差不多,就引入有区别而已 <!--这是作为模块使用--><!DOCTYPE html> <h ...
- luogu P1518 两只塔姆沃斯牛 The Tamworth Two
luogu P1518 两只塔姆沃斯牛 The Tamworth Two 题目描述 两只牛逃跑到了森林里.农夫John开始用他的专家技术追捕这两头牛.你的任务是模拟他们的行为(牛和John). 追击在 ...
- 2016级算法第二次上机-A.画个圈圈诅咒你
890 画个圈圈诅咒你 思路 简单题.题目中的圆并没有什么实际作用,简化成线段重合问题会更好理解些. 暴力解法:使用双重for循环会T到想哭,记住最直接的方法一般是过不了题的. 解法一:二分查找.空间 ...
- eclipse项目目录展示结构设置
我因为前后端都搞过, 解除过很多的开发IDE,说真的,很多的项目目录结构都是一级一级分开,然后我可以通过展开等操作来查看文件等资源信息,结果呢?java的开发IDE eclipse默认的项目目录展示简 ...
- NVIDIA Jetson TX2刷机
官方安装教程 JetPack下载 主机端环境准备 需要在PC端安装虚拟机,虚拟机中安装Ubuntu14.04系统. 按照上面的地址下载JetPack-L4T-3.1-linux-x64.run 主机端 ...
- SD341X-SD343H蜗轮传动伸缩蝶阀厂家,SD341X-SD343H蜗轮传动伸缩蝶阀价格 - 专题栏目 - 无极资讯网
无极资讯网 首页 最新资讯 最新图集 最新标签 搜索 SD341X-SD343H蜗轮传动伸缩蝶阀 无极资讯网精心为您挑选了(SD341X-SD343H蜗轮传动伸缩蝶阀)信息,其中包含了(SD341 ...
- 对接京东jos遇到的坑 记录一下。方便查询
坑很多,有一些忘记了.文档乱的很,有问题可以私信我一下我看能不能想起来. 坑一.添加商品接口. {"error_response": {"code":" ...
- eclipse中springsource-tool-suite(sts)插件安装教程
插件的下载参照:http://www.cnblogs.com/jepson6669/p/8540157.html 用过的eclipse不能安装成功,需要重新解压新的才能安装成功,不知道为什么? 解压上 ...