UVA 12186 Another Crisis 树型DP
来源:互联网 发布:简历信息采集软件 编辑:程序博客网 时间:2024/06/08 15:03
https://uva.onlinejudge.org/external/121/12186.pdf
以上是题目链接,因为PDF比较难写
其实我感觉这一道题目连dp数组都不要开。。
定义状态dp[i]表示要i递交请愿书最少需要几个人,所以很自然的只要把i的子节点dp加入一个vector,然后sort一下,取前面几个就好
因为保证每个节点只会访问一次,因此不会有重复计算的问题,以上
因为一眼看出来的,所以不算100道动态规划
PS:1A哟,1A
#include <iostream>#include <algorithm>#include <numeric>#include <cstring>#include <vector>#include <cmath>using namespace std;const int maxm=1E5+10;struct Edge{ int nt,v; explicit Edge(int a=0,int b=0):nt(a),v(b){}}edge[maxm];int n,t,ind,fi[maxm],dfs(int i);void addeage(int x,int y);int main(){ ios_base::sync_with_stdio(0); while(cin>>n>>t&&n+t){ for(int i=1,te;i<=n;++i){ cin>>te; addeage(te,i); } cout<<dfs(0)<<endl; memset(fi,0,sizeof fi); ind=0; } return 0;}void addeage(int x, int y){ edge[++ind]=Edge(fi[x],y); fi[x]=ind;}int dfs(int i){ if(fi[i]==0) return 1; vector<int> v; int peo=0; for(int j=fi[i];j;j=edge[j].nt) v.push_back(dfs(edge[j].v)),++peo; peo=ceil(peo*t/100.0); if(v.size()<peo) return 0x3f3f3f3f; sort(v.begin(),v.end()); return accumulate(v.begin(),v.begin()+peo,0);}
0 0
- UVA 12186 Another Crisis 树型DP
- UVa 12186 Another Crisis dp:树上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)
- 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 )
- UVA - 12186 Another Crisis (树形DP)
- Windows下编译MICO源代码遇到的问题
- 清空一个消息队列, OSQFlush()
- Java功底之Reference
- 算法导论(Exercise 2.3-6)
- 远程私有组件库实践指南
- UVA 12186 Another Crisis 树型DP
- JAVA线程池原理以及几种线程池类型介绍
- 嵌入式Linux开发环境搭建
- 欢迎使用CSDN-markdown编辑器
- 控制台输出console.log()的用法
- Java功底之static、final、this、super
- 常用操作技巧总结
- Ubuntu 16.04 虚拟机安装记录
- [JZOJ5061]最长路径