题意:有一个老板和n个员工,除了老板每个员工都有唯一的上司,老板编号为0,员工们为1-n,工人(没有下属的员工),要交一份请愿书,

但是不能跨级,当一个不是工人的员工接受到直系下属不少于T%的签字时,自己也会签字,并交给上级,问你最少有多少工人签字,才能让老板收到请愿书。

析:题意比较简单,也好理解,很明显是一个动态规划的题目,d(u)表示u给上级要发信至少需要多少工人签字。假设u有k个结点,那么至少要

c = (kT-1)/100 + 1个工人,然后把每个结点排序,找出最少的工人即可,挺简单的。

代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring> using namespace std;
const int maxn = 100000 + 10;
int dp[maxn], T, n; vector<int> sons[maxn];
int DP(int u){
if(sons[u].empty()) return 1; int k = 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(){
// freopen("int.txt", "r", stdin);
while(scanf("%d %d", &n, &T)){
if(!n && !T) break; for(int i = 0; i <= n; ++i)
sons[i].clear();
int x;
for(int i = 0; i < n; ++i){
scanf("%d", &x);
sons[x].push_back(i+1);
} int ans = 0; memset(dp, 0, sizeof(dp));
for(int i = n; i >= 0; --i)
dp[i] += DP(i);
printf("%d\n", dp[0]); }
return 0;
}

UVa 12186 Another Crisis (DP)的更多相关文章

  1. UVa 12186 - Another Crisis(树形DP)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. UVA - 12186 Another Crisis (树形DP)

    思路:dp[i]表示让上司i签字至少需要多少工人签字.       转移方程:将i的所有节点根据所需工人数量升序排序,设i需要k个下属签字,dp[i] = sum{dp[v]| 0 <= v & ...

  3. uva 116 Unidirectional TSP (DP)

    uva 116 Unidirectional TSP Background Problems that require minimum paths through some domain appear ...

  4. UVa 1638 - Pole Arrangement(dp)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. UVA 1638 Pole Arrangement (dp)

    题意:有n个长度为1到n的柱子排列在一起,从左边看有l根从右边看有r根,问你所以排列中满足这种情况的方案数 题解:就是一个dp问题,关键是下标放什么,值代表什么 使用三维dp,dp[i][j][k]= ...

  6. UVA 674 Coin Change(dp)

    UVA 674  Coin Change  解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...

  7. UVA 10163 - Storage Keepers(dp)

    本文出自   http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题意 有n个仓库,让m个人来看管.一个仓库只能由一个人来看管,一个人可以看管多个仓库. 每个人 ...

  8. UVA 11137 Ingenuous Cubrency(dp)

    Ingenuous Cubrency 又是dp问题,我又想了2 30分钟,一点思路也没有,最后又是看的题解,哎,为什么我做dp的题这么烂啊! [题目链接]Ingenuous Cubrency [题目类 ...

  9. UVA 674 Coin Change (DP)

    Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make c ...

随机推荐

  1. 无线密码破解----minidwep-gtk的PIN破解方法

    使用虚拟机对minidwep-gtk进行PIN破解  用CDLINUX支持8187和3070_30211版.iso系统PJpin码 1.用虚拟机的好处是方便,可以一边破解,一边上网做其他事情. 虚拟机 ...

  2. cocostudio 使用教程

    项目配置 http://blog.csdn.net/chinahaerbin/article/details/21559351 项目配置如下: 还要引入命名空间之类的: #include " ...

  3. 用Keras 和 DDPG play TORCS(1)

    用Keras 和 DDPG play TORCS(环境配置篇) 原作者Using Keras and Deep Deterministic Policy Gradient to play TORCS ...

  4. BZOJ1252:序列终结者

    浅谈\(splay\):https://www.cnblogs.com/AKMer/p/9979592.html 浅谈\(fhq\)_\(treap\):https://www.cnblogs.com ...

  5. Phonegap项目创建 编译 安装 运行

    一.创建 Phonegap项目 1. cd workspace 2.创建phonegap项目 cordova create 目录 识别符 显示名 例如:cordova create hello com ...

  6. delphi webbrowser 常用方法示例

    var Form : IHTMLFormElement ; D:IHTMLDocument2 ; begin with WebBrowser1 do begin D := Document as IH ...

  7. HDU 4762 Cut the Cake(高精度)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. PHP扩展类ZipArchive实现压缩解压Zip文件和文件打包下载 && Linux下的ZipArchive配置开启压缩 &&搞个鸡巴毛,写少了个‘/’号,浪费了一天

    PHP ZipArchive 是PHP自带的扩展类,可以轻松实现ZIP文件的压缩和解压,使用前首先要确保PHP ZIP 扩展已经开启,具体开启方法就不说了,不同的平台开启PHP扩增的方法网上都有,如有 ...

  9. 深入浅出HTTPS工作原理(转载)

    转载自: https://blog.csdn.net/wangtaomtk/article/details/80917081 深入浅出HTTPS工作原理 HTTP协议由于是明文传送,所以存在三大风险: ...

  10. Django ORM-02

    6.ForeignKey 相关操作 1.正向查找 正向查找:那么什么是正向查找,我们知道对于一对多或者多对一的情况,我们一般将ForeignKey设置在多的一边,比如我们的书籍与出版社一般是多对一的, ...