UVa 12186 Another Crisis (DP)
题意:有一个老板和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)的更多相关文章
- UVa 12186 - Another Crisis(树形DP)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA - 12186 Another Crisis (树形DP)
思路:dp[i]表示让上司i签字至少需要多少工人签字. 转移方程:将i的所有节点根据所需工人数量升序排序,设i需要k个下属签字,dp[i] = sum{dp[v]| 0 <= v & ...
- uva 116 Unidirectional TSP (DP)
uva 116 Unidirectional TSP Background Problems that require minimum paths through some domain appear ...
- UVa 1638 - Pole Arrangement(dp)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 1638 Pole Arrangement (dp)
题意:有n个长度为1到n的柱子排列在一起,从左边看有l根从右边看有r根,问你所以排列中满足这种情况的方案数 题解:就是一个dp问题,关键是下标放什么,值代表什么 使用三维dp,dp[i][j][k]= ...
- UVA 674 Coin Change(dp)
UVA 674 Coin Change 解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...
- UVA 10163 - Storage Keepers(dp)
本文出自 http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题意 有n个仓库,让m个人来看管.一个仓库只能由一个人来看管,一个人可以看管多个仓库. 每个人 ...
- UVA 11137 Ingenuous Cubrency(dp)
Ingenuous Cubrency 又是dp问题,我又想了2 30分钟,一点思路也没有,最后又是看的题解,哎,为什么我做dp的题这么烂啊! [题目链接]Ingenuous Cubrency [题目类 ...
- 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 ...
随机推荐
- R学习笔记 ---- 系列文章
R实战 开篇:介绍R的使用 R学习笔记 第五篇:字符串操作 R学习笔记 第六篇:数据变换和清理 R学习笔记 第四篇:函数,分支和循环 R学习笔记 第三篇:数据框 R学习笔记 第二篇:矩阵.数组和列表 ...
- WCF揭秘学习笔记(3):使用DataContractSerializer
使用DataContractSerializer 终结点(包括地址.绑定.契约)可通过代码以编程方式添加到服务中.如: using(ServiceHost host =new ServiceHost( ...
- ASP.NET 获得当前网页名字
Code string currentFilePath = HttpContext.Current.Request.FilePath; string CurrentPageName = current ...
- 剪贴板增强---Kawvin增强剪贴板_V2.0
#Persistent SetWorkingDir,%A_ScriptDir% ;设置工作目录 #MaxThreadsPerHotkey ;最大热键数量 #NoEnv ;#Warn #SingleIn ...
- springMVC国际化配置和使用
下面是基于session的,springMVC国际花的一个例子: 需求是 输入url:展示中文界面 http://localhost:8080/MySSM/user?lang=zh 输入url: 展 ...
- Oracle VM Virtualbox基础知识
修改硬盘的UUID VBoxManage internalcommands sethduuid <filename>
- 【UVALive】4094 WonderTeam(神结论)
题目 传送门:QWQ 分析 好神的结论啊 看代码吧(Length只有85) 代码 顺手压了压代码 目前代码长度rk1 vjudge #include <iostream> ?:n ...
- Spring batch学习 (1)
Spring Batch 批处理框架 埃森哲和Spring Source研发 主要解决批处理数据的问题,包含并行处理,事务处理机制等.具有健壮性 可扩展,和自带的监控功能,并且支持断点和重发.让程序员 ...
- jQuery+SpringMVC中的复选框选择与传值
一.checkbox选择 在jQuery中,选中checkbox通用的两种方式: $("#cb1").attr("checked","checked& ...
- FireMoneky 画图 Point 赋值
VCL 的 Canvas.Pen 对应FMX: Canvas.Stroke;VCL到 Canvas.Brush 对应FMX: Canvas.Fill. TCircle 圆形控件 Inkscape 0. ...