BNUOJ 5235 Starship Troopers
Starship Troopers
This problem will be judged on HDU. Original ID: 1011
64-bit integer IO format: %I64d Java class name: Main
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
5 10
50 10
40 10
40 20
65 30
70 30
1 2
1 3
2 4
2 5
1 1
20 7
-1 -1
Sample Output
50
7
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
int n,m,bugs[],p[],dp[][];
vector<int>g[];
void dfs(int u,int fa){
int i,j,k;
for(i = bugs[u]; i <= m; i++)
dp[u][i] = p[u];
for(i = ; i < g[u].size(); i++){
if(g[u][i] == fa) continue;
dfs(g[u][i],u);
for(j = m; j >= bugs[u]; j--){
for(k = ; k <= j-bugs[u]; k++){
dp[u][j] = max(dp[u][j],dp[u][j-k]+dp[g[u][i]][k]);
}
}
}
}
int main(){
int i,j,u,v;
while(scanf("%d %d",&n,&m),n != - && m != -){
for(i = ; i <= n; i++)
g[i].clear();
for(i = ; i <= n; i++){
scanf("%d %d",bugs+i,p+i);
bugs[i] = (bugs[i] + )/;
}
memset(dp,,sizeof(dp));
for(i = ; i < n; i++){
scanf("%d %d",&u,&v);
g[u].push_back(v);
g[v].push_back(u);
}
if(m == ) {puts("");continue;}
dfs(,-);
cout<<dp[][m]<<endl;
}
return ;
}
BNUOJ 5235 Starship Troopers的更多相关文章
- HD 1011 Starship Troopers(树上的背包)
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Starship Troopers
Problem Description You, the leader of Starship Troopers, are sent to destroy a base of the bugs. Th ...
- [HDU 1011] Starship Troopers
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1011 树形背包(DP) Starship Troopers
题目链接: HDU 1011 树形背包(DP) Starship Troopers 题意: 地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...
- 杭电OJ——1011 Starship Troopers(dfs + 树形dp)
Starship Troopers Problem Description You, the leader of Starship Troopers, are sent to destroy a ba ...
- 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 ****
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- 题解报告:hdu 1398 Square Coins(母函数或dp)
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
- Java标识符的习惯命名规范
1 常量标识符:全部用大写字母和下划线表示.如SALES_MAX 2 类名或接口名:标识符用大写字母开头.如CreditCard 3 变量名和方法名:以小写字母开头,单词之间不要有分隔符,第二 及后面 ...
- 通过Fiddler监控Java应用发送请求及相应数据
Fiddler可以很好的监控浏览器发送的各种请求及响应数据,对于JAVA程序默认情况下是无法监控的,但实际需求中需要监控JAVA程序发送HTTP请求及返回数据是否正确. Fiddler默认配置的监听端 ...
- 利用正则将xml数据解析为数组
function xml_to_array( $xml ) { $reg = '/<(\w+)[^>]*>([\x00-\xFF]*)<\/\1>/'; if(preg_ ...
- .NET框架概述
.NET战略目标: 任何时候(when),任何地方(where),使用任何工具(what)都能通过.NET的服务获得网络上的任何信息. .NET优势: 1.提供了一个面向对象的编程环境,完全支持面向对 ...
- AJPFX实列判断一个字符串是不是对称字符串
import java.util.Scanner; /** * 判断一个字符串是否是对称字符串 */ public class StringDemo { public static vo ...
- git ---合并和删除分支
git merge 分支名 //合并子分支到当前分支 git branch -d 分支名//删除分支
- win7+idea+maven搭建spark源码阅读环境
1.参考. 利用IDEA工具编译Spark源码(1.60~2.20) https://blog.csdn.net/He11o_Liu/article/details/78739699 Maven编译打 ...
- Objective-C Foundation 框架 Example :Looking for Files 查找文件
Objective-C Foundation 框架 Example :Looking for Files 查找文件 NSFileManager. The NSFileManager class ...
- 阿里云ecs绑定域名
在阿里云服务器ECS一切配置ok后,通过域名一直访问不成功,结果发现还需要在后台进行安全组的规则设定: