HDU-1561 The more,The Better
来源:互联网 发布:什么叫还原网络设置 编辑:程序博客网 时间:2024/05/20 23:02
The more, The Better
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6874 Accepted Submission(s): 4036
Problem Description
ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允许攻克M个城堡并获得里面的宝物。但由于地理位置原因,有些城堡不能直接攻克,要攻克这些城堡必须先攻克其他某一个特定的城堡。你能帮ACboy算出要获得尽量多的宝物应该攻克哪M个城堡吗?
Input
每个测试实例首先包括2个整数,N,M.(1 <= M <= N <= 200);在接下来的N行里,每行包括2个整数,a,b. 在第 i 行,a 代表要攻克第 i 个城堡必须先攻克第 a 个城堡,如果 a = 0 则代表可以直接攻克第 i 个城堡。b 代表第 i 个城堡的宝物数量, b >= 0。当N = 0, M = 0输入结束。
Output
对于每个测试实例,输出一个整数,代表ACboy攻克M个城堡所获得的最多宝物的数量。
Sample Input
3 20 10 20 37 42 20 10 42 17 17 62 20 0
Sample Output
513
Author
8600
Source
HDU 2006-12 Programming Contest
请无视代码里的字符处理……上课做的实验题,找到相似题改了一下就搬过来了。
#include <algorithm>#include <iostream>#include <sstream>#include <cstring>#include <cstdlib>#include <string>#include <vector>#include <cstdio>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>using namespace std;#define INF 0x3f3f3f3const int N=10005;const int mod=1e9+7;int score[205];vector<int> son[205];int dp[205][205];string s[205][205];void dfs(int n,int left){ dp[n][1]=score[n]; if (n!=0) { stringstream ss; ss<<n; s[n][1]=ss.str(); s[n][1]+=" "; } for (int i=0; i<son[n].size(); i++) { if (left>1) dfs(son[n][i], left-1); for (int j=left; j>=1; j--) { for (int k=1; k<=j; k++) { if (dp[n][j+1]<dp[n][j+1-k]+dp[son[n][i]][k]){ dp[n][j+1]=dp[n][j+1-k]+dp[son[n][i]][k]; s[n][j+1]=s[n][j+1-k]+s[son[n][i]][k]; } } } }}int main() { int n,m,a,b,c; n=100; while (cin>>n>>m&&n) { memset(score, 0, sizeof(score)); memset(dp, 0, sizeof(dp)); for (int i=0; i<=n; i++) { son[i].clear(); } for (int i=0; i<n; i++) { a=i+1; cin>>b>>c; son[b].push_back(a); score[a]=c; } dfs(0, m+1); cout<<dp[0][m+1]<<endl; } return 0;}
0 0
- hdoj(hdu)-1561-the more the better
- hdu 1561 The more,The better
- hdu 1561 the more,the better
- Hdu 1561 The more, The Better
- HDU 1561 The more, The Better
- HDU 1561 The more, The Better
- HDU-1561-The more, The Better
- HDU 1561 The more, The Better
- HDU 1561 The more, The Better
- HDU:1561 The more,The Better
- HDU 1561 The more, The Better
- hdu 1561 The more, The Better
- HDU 1561 The more ,The Better
- hdu 1561 The more, The Better DP
- HDU 1561 The more, The Better
- hdu 1561 The more, The Better
- HDU 1561 The more, The Better
- HDU 1561 The more, The Better
- 如何同时启动多个Tomcat服务
- 数据结构(9)线性表之循环链表介绍
- 数据库几个函数记录
- 关于在线编辑功能
- linux MISC 驱动模型分析
- HDU-1561 The more,The Better
- 欢迎使用CSDN-markdown编辑器
- Java NIO系列教程(五) 通道之间的数据传输
- 面试产品经理时如何回答“为什么想做产品经理”这个问题
- context.getClass和getPackageName的区别
- Andriod 中button监听事件的三种方式
- 矩阵、向量求导法则
- linux mysql 数据库开启外部访问设置指南
- 【挖坑】近期学习计划