Another Crisis
题意:
给出一个树,当孩子节点为1的数量占孩子总数的T%时父节点变成1,求使根节点变成1需要叶子节点为1的最小数量。
分析:
简单的树状dp,dp[i]以i为根的子树所需的最小数量,取它所有子树中最小的T%,即可,分析时觉得这个方法会超时,可能题目数据太水。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 100010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int dp[N],t,n;
vector<int>e[N];
int s[N];
void dfs(int root){
int num=e[root].size();
if(num==){
dp[root]=;
return ;
}
for(int i=;i<num;++i)
{
int son=e[root][i];
dfs(son);
}
for(int i=;i<num;++i)
s[i]=dp[e[root][i]];
int len=ceil(1.0*t/*num);
sort(s,s+num);
for(int j=;j<len;++j)
dp[root]+=s[j];
}
int main()
{
while(~scanf("%d%d",&n,&t)){
if(n==&&t==)break;
for(int i=;i<=n;++i)
e[i].clear();
int p;
for(int i=;i<=n;++i)
{
scanf("%d",&p);
e[p].push_back(i);
}
memset(dp,,sizeof(dp));
dfs();
printf("%d\n",dp[]);
}
return ;
}
Another Crisis的更多相关文章
- HDU 3749 Financial Crisis
Financial Crisis 题意:给一个图,包含N ( 3 <= N <= 5000 )个点, M ( 0 <= M <= 10000 )条边 and Q ( 1 < ...
- Crisis of HDU(母函数)
Crisis of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- (3)The critical role librarians play in the opioid crisis
https://www.ted.com/talks/chera_kowalski_the_critical_role_librarians_play_in_the_opioid_crisis 00:1 ...
- 每日英语:KFC's Crisis in China Tests Ingenuity of Man Who Built Brand
Sam Su for years ran one of the highest-flying foreign business operations in China. These days, he' ...
- bzoj1605 / P2905 [USACO08OPEN]农场危机Crisis on the Farm
P2905 [USACO08OPEN]农场危机Crisis on the Farm 发现总步数$k<=30$,考虑用$k$瞎搞 设$f[u][i][j]$表示已经吹$u$次哨,全体奶牛向右走$i ...
- HDU 2110 Crisis of HDU
Crisis of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- 洛谷P2905 [USACO08OPEN]农场危机Crisis on the Farm
P2905 [USACO08OPEN]农场危机Crisis on the Farm 题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每 ...
- UVa12186:Another Crisis(树形DP)
一道简单的树形DP送给你. A couple of years ago, a new world wide crisis started, leaving many people with econo ...
- HDU 3749 Financial Crisis(点-双连通分量)
Because of the financial crisis, a large number of enterprises go bankrupt. In addition to this, oth ...
- UVa 12186 Another Crisis
题意: 给出一个树状关系图,公司里只有一个老板编号为0,其他人员从1开始编号.除了老板,每个人都有一个直接上司,没有下属的员工成为工人. 工人们想写一份加工资的请愿书,只有当不少于员工的所有下属的T% ...
随机推荐
- HDU 4143 A Simple Problem(枚举)
题目链接 题意 : 就是给你一个数n,让你输出能够满足y^2 = n +x^2这个等式的最小的x值. 思路 : 这个题大一的时候做过,但是不会,后来学长给讲了,然后昨天比赛的时候二师兄看了之后就敲了, ...
- chmod命令详细用法
指令名称 : chmod 使用权限 : 所有使用者 使用方式 : chmod [-cfvR] [--help] [--version] mode file... 说明 : Linux/Unix 的档案 ...
- 目标检测的图像特征提取之(三)Haar特征
1.Haar-like特征 Haar-like特征最早是由Papageorgiou等应用于人脸表示,Viola和Jones在此基础上,使用3种类型4种形式的特征. Haar特征分为三类:边缘特征.线性 ...
- [转]C++常见内存错误汇总
在系统开发过程中出现的bug相对而言是比较好解决的,花费在这个上面的调试代价不是很大,但是在系统集成后的bug往往是难以定位的bug(最好方式是打桩,通过打桩可以初步锁定出错的位置,如:进入函数前打印 ...
- JAVA:23种设计模式详解(转)2
我们接着讨论设计模式,上篇文章我讲完了5种创建型模式,这章开始,我将讲下7种结构型模式:适配器模式.装饰模式.代理模式.外观模式.桥接模式.组合模式.享元模式.其中对象的适配器模式是各种模式的起源,我 ...
- eclipse安装反编译插件
1. 进入http://jadclipse.sourceforge.net/wiki/index.php/Main_Page#Download 下载 net.sf.jadclipse ...
- 常用的Linux终端
常用的Linux终端 gnome-terminal (Gnome标配) xfce4-terminal (XFCE4标配) lxterminal (LXDE标配) konsole (KDE标配) 前面3 ...
- ubuntu下显卡管理
1 Ubuntu下卸载ATI显卡驱动并还原开源驱动[转] 首先卸载已经安装的ATI显卡驱动:cd /usr/share/ati/sudo ./fglrx-uninstall.sh 接着执行下面的代码: ...
- sql中exists,not exists的用法
exists : 强调的是是否返回结果集,不要求知道返回什么, 比如: select name from student where sex = 'm' and mark exists(select ...
- PCL—低层次视觉—关键点检测(rangeImage)
关键点又称为感兴趣的点,是低层次视觉通往高层次视觉的捷径,抑或是高层次感知对低层次处理手段的妥协. ——三维视觉关键点检测 1.关键点,线,面 关键点=特征点: 关键线=边缘: 关键面=foregro ...