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% ...
随机推荐
- sudo: /etc/sudoers 的模式为 0551,应为 0440
环境:Ubuntu 12.04.4 LTS 32bit 本想修改/etc/sudoers文件,取消sudo权限的密码.但是因为sudoers文件无‘w’(写)的权限,然后用命令加写权限的时候加错了,加 ...
- apache common-io.jar FileUtils
//复制文件 void copyFile(File srcFile, File destFile) //将文件内容转化为字符串 String readFileToString(File file ...
- hdu 2149 Public Sale (博弈规律题)
#include<stdio.h> int main() { int n,m; while(scanf("%d %d",&m,&n)!=EOF) { ) ...
- 如何实现Windows Phone代码与Unity相互通信(直接调用)
我之前用了两篇文章写了WP与Unity相互通信.调用的办法,一个是事件,一个是插件. 这次来说个更简单的,我觉得这应该是Unity发布到WP或者Win Store上得天独厚的优势.毕竟都是C#. 懒得 ...
- amd(超微半导体公司(英语:Advanced Micro Devices, Inc.,缩写:AMD))
公司名称 AMD(超微半导体公司) 经营范围 CPU.显卡.主板等电脑硬件设备 AMD公司专门为计算机.通信和消费电子行业设计和制造各种创新的微处理器(CPU.GPU.APU.主板芯片组.电视卡芯 ...
- iOS KVO的原理
KVO(Key Value Observing),是观察者模式在Foundation中的实现. KVO的原理 简而言之就是: 1.当一个object有观察者时,动态创建这个object的类 ...
- oracle 修改表的sql语句
oracle 修改表的sql语句 1增加一个列:ALTER TABLE 表名 ADD(列名 数据类型);如:ALTER TABLE emp ADD(license varchar2(256)) ...
- 如何查看linux是32位还是64位
可以用命令“getconf LONG_BIT”查看,如果返回的结果是32则说明是32位,返回的结果是64则说明是64位. 此外还可以使用命令“uname -a”查看,输出的结果中,如果有x86_64就 ...
- c 语言练习__求到N的阶乘的和。
#include <stdio.h> /* 题目如下 * S = 1 + 2! + 3! + ... + N! */ int main(int argc, char *argv[]) { ...
- fil_space_t
typedef struct fil_space_struct fil_space_t; /** Tablespace or log data space: let us call them by a ...