uva 12186——Another Crisis
来源:互联网 发布:淘宝差评对卖家重要吗 编辑:程序博客网 时间:2024/06/11 10:57
题意:公司里有n个员工,组成树状的结构,老板的编号为0,工人给直隶上司递请愿书,当人数总量超过T*0.01时,往上呈递,求解需要多少工人才能让老板看到请愿书。
思路:树形DP。dp(u)是u需要的呈递需要的最小的人数,那么需要c = (k*T - 1) / 100 + 1个直接下属呈递,所有子节点的前c个即为dp(u)。
code:
#include <bits/stdc++.h>using namespace std;#define ft(i,s,t) for (int i=s;i<=t;i++)#define frt(i,t,s) for (int i=t;i>=s;i--)#define cls(v,c) memset(v,c,sizeof(v))const int INF=0x3f3f3f3f;const int N=1e5+5;int n,t,x,d[N];vector<int>g[N];int dp(int u){ if (g[u].empty()) return 1; int len=g[u].size(); vector<int>d; ft(i,0,len-1) d.push_back(dp(g[u][i])); sort(d.begin(),d.end()); int c=(len*t-1)/100+1; int ans=0; ft(i,0,c-1) ans+=d[i]; return ans;}int main(){ while (~scanf("%d %d",&n,&t),n+t) { ft(i,0,n) g[i].clear(); ft(i,1,n) scanf("%d",&x),g[x].push_back(i); printf("%d\n",dp(0)); }}
0 0
- uva 12186——Another Crisis
- Uva-12186-Another Crisis
- UVA 12186 Another Crisis
- UVA - 12186 Another Crisis
- UVA-12186 Another Crisis
- uva 12186 Another Crisis
- UVA 12186 Another Crisis
- UVA 12186 Another Crisis
- UVA 12186(p282)----Another Crisis
- UVa OJ 12186 - Another Crisis
- UVA 12186 - Another Crisis(树形DP)
- 【UVA】12186-Another Crisis(动态规划)
- Another Crisis - UVa 12186 树形dp
- UVA 12186 Another Crisis(树形DP)
- UVa 12186 Another Crisis(树形DP)
- UVA 12186 Another Crisis 树形DP
- UVa #12186 Another Crisis (例题9-12)
- UVa 12186 - Another Crisis(树形DP)
- 南大软院大神养成计划--jquery
- Android Camera数据流分析全程记录(overlay方式二)
- Android之screenOrientation属性
- 最小生成树(Prim算法)
- Android Camera CameraHal.cpp 初始化分析
- uva 12186——Another Crisis
- 我的Xelatex 中文报告模板
- opencv3.0配置文件opencv300.props
- 递归技术
- JAVA面向对象(一)
- 关于AssetBundle
- hive/hbase区别
- 深度学习计算机视觉资料
- 命令制作启动盘