hdu 4616Game
来源:互联网 发布:linux oracle怎么启动 编辑:程序博客网 时间:2024/06/14 20:57
应该用树形dp的,数据太水,直接水过也行
#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>#define LL long long#define N 50010using namespace std;vector<int> G[N];int v[N];LL s[N];bool iscut[N];int n,m;LL p;void init(){ for(int i=0; i<n; ++i) G[i].clear(),iscut[i]=0;}LL dfs(int cur,int pos,LL Sum){ if(!pos) return Sum; for(int i=0; i<G[cur].size(); ++i) { int c=G[cur][i]; if(!iscut[c]) { iscut[c]=1; p=max(dfs(c,pos-v[c],Sum+s[c]),p); iscut[c]=0; } } return Sum;}int main(){ // freopen("in.txt","r",stdin); int t,x,y; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); init(); for(int i=0; i<n; ++i) scanf("%I64d%d",&s[i],&v[i]); for(int i=0; i<n-1; ++i) { scanf("%d%d",&x,&y); G[x].push_back(y); G[y].push_back(x); } p=0; for(int i=0; i<n; ++i) { iscut[i]=1; p=max(dfs(i,m-v[i],s[i]),p); iscut[i]=0; } printf("%I64d\n",p); } return 0;}
- HDU 4616 Game
- hdu 4616 Game
- HDU 4616 Game
- hdu 4616 Game
- hdu 4616Game
- hdu 4616 Game
- HDU 4616 Game 解题报告
- 【树形DP】 HDU 4616 Game
- 树形dp hdu-4616-Game
- 【HDU】4616 Game 树型DP
- hdu 4616 game (树形dp)
- hdu 4616 Game 树形dp
- *hdu 4616 Game 树形DP
- Game HDU
- Game HDU
- hdu 4616 Game 多校第二场
- 【解题报告】HDU 4616 Game - 树形dp
- hdu 4616 Game ( 经典树形dp )
- 解决编译器“The connection to adb is down, and a severe error has occured.ADB server didn't ACK”提示错误方法
- CSS中margin与padding的区别
- “U盘化生存”带来的职场启示
- 详解在IOS后台执行
- linux内存检测
- hdu 4616Game
- c#Process.Start无法启动exe程序的问题
- 持续集成方案,Hudson还是Jenkins?
- 设计模式读书笔记-----访问者模式
- Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id)等
- 输入倒三角的星号图的几种方法
- hadoop集群中添加kerberos认证
- java 类中函数加与不加static
- uploadify 丢失session解决方法