UVa 12186 - Another Crisis(树形DP)
来源:互联网 发布:c语言中字符串处理函数 编辑:程序博客网 时间:2024/06/08 03:48
书上给出了思路和DP部分的代码,其他的就很简单了。
#include<cstdio>#include<vector>#include<algorithm>using namespace std;const int maxn=100010;int n,t;vector<int> sons[maxn];int dp(int u){ if(sons[u].empty()) return 1; int k=(int)sons[u].size(); vector<int> d; for(int i=0;i<k;++i) d.push_back(dp(sons[u][i])); sort(d.begin(),d.end()); int c=(k*t-1)/100+1; int ans=0; for(int i=0;i<c;++i) ans+=d[i]; return ans;}int main(){ while(~scanf("%d%d",&n,&t)){ if(!n&&!t) break; for(int i=0;i<=n;++i) sons[i].clear(); for(int i=1;i<=n;++i){ int k; scanf("%d",&k); sons[k].push_back(i); } printf("%d\n",dp(0)); } return 0;}
0 0
- UVA 12186 - Another Crisis(树形DP)
- UVA 12186 Another Crisis(树形DP)
- UVa 12186 Another Crisis(树形DP)
- UVa 12186 - Another Crisis(树形DP)
- UVa 12186 - Another Crisis(树形DP)
- UVA - 12186 Another Crisis (树形dp)
- UVA - 12186 Another Crisis (树形DP)
- Another Crisis - UVa 12186 树形dp
- UVA 12186 Another Crisis 树形DP
- uva 12186 Another Crisis 树形dp
- UVA - 12186 Another Crisis 水树形dp
- UVA 12186 Another Crisis [树形dp]
- uva 12186 Another Crisis 树形DP
- UVa - 12186 - Another Crisis ( 树形DP )
- 【树形DP】UVa 12186 Another Crisis
- UVA 12186 Another Crisis(树形DP)
- UVAOJ 12186Another Crisis(树形DP)
- UVa 12186:Another Crisis(DP)
- 理解inode
- MyBatis 的 resultMap
- 项目、习惯以及Todolist的区别
- tomcat性能优化详解
- 数字之魅——寻找发帖水王
- UVa 12186 - Another Crisis(树形DP)
- 调用函数实现数组升序输出
- ios沙箱路径的查看和使用
- 24 - 判断是否是二叉搜索树的后序遍历序列
- <转>JAVA学习之路,不走弯路就是捷径
- 欢迎使用CSDN-markdown编辑器
- LeetCode(64) Minimum Path Sum
- python-re模块
- [Leetcode 25] Reverse Nodes in k-Group