uva 12186 工人的请愿书
来源:互联网 发布:如何评价余秋雨知乎 编辑:程序博客网 时间:2024/04/29 05:32
d[u]表示让u给上级发信至少需要多少人,假设u有k个子节点,则至少需要c = (k*T-1)/ 100 + 1个人才行,然后按照子节点d的值从小到大排序,把前c个相加就是d[u]。
/*********************************************** * Author: fisty * Created Time: 2015/2/27 17:02:07 * File Name : uva12186.cpp *********************************************** */#include <iostream>#include <cstring>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <bitset>#include <algorithm>using namespace std;#define Debug(x) cout << #x << " " << x <<endl#define Memset(x, a) memset(x, a, sizeof(x))const int INF = 0x3f3f3f3f;typedef long long LL;typedef pair<int, int> P;#define FOR(i, a, b) for(int i = a;i < b; i++)#define MAX_N 100010int n, T;vector<int> son[MAX_N];int dp(int u){ if(son[u].empty()) return 1; int k = son[u].size(); vector<int> d; for(int i = 0;i < k; i++){ d.push_back(dp(son[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(){ //freopen("in.cpp", "r", stdin); cin.tie(0); ios::sync_with_stdio(false); while(cin >> n >> T){ if(!n && !T) break; FOR(i, 0, n+1) son[i].clear(); FOR(i, 1, n+1){ int u; cin >> u; son[u].push_back(i); } cout << dp(0) << endl; } return 0;}
0 0
- uva 12186 工人的请愿书
- UVA 12186 工人的请愿书
- 树形DP(工人的请愿书,uva 12186)
- 例题 9-12 工人的请愿书 UVa 12186
- 工人的请愿书 Another Crisis(UVa 12186)题解
- 12186 - Another Crisis(工人的请愿书z )
- 例题9-12 工人的请愿书 UVa12186
- 树形dp,工人请愿书 uva12186
- 砌墙工人的命运
- 西里西亚的纺织工人
- 工人的薪水问题
- 《工人眼中的历史》
- 还的工人房
- 学生到工人的转换
- 解释代码工人的误区
- 工人的工资少openeim002
- 代码工人真的必要吗?
- 【转载】代码工人的婚姻函数
- hdu 1564 证明 (2)
- ASPXGridView外观显示
- Appium总结
- C#判断节点下是否还有子节点的方法
- eclipse中Android模拟器,DDMS看不到设备的解决及有时无打印Log,自己有小改
- uva 12186 工人的请愿书
- Java 理论与实践: 正确使用 Volatile 变量
- windows 7系统使用U盘安装时,出现安装程序法创建新的系统分区(解决方案亲测可用)
- BZOJ 3892 Usaco2014 Dec Marathon DP
- node.js 学习笔记
- 虚函数和抽象类
- BZOJ 3893 Usaco2014 Dec Cow Jog 模拟
- 山楂果脯
- 【BZOJ3891】【Usaco2014 Dec】Piggy Back bfs+动规?