题意:

给出一个树,当孩子节点为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的更多相关文章

  1. HDU 3749 Financial Crisis

    Financial Crisis 题意:给一个图,包含N ( 3 <= N <= 5000 )个点, M ( 0 <= M <= 10000 )条边 and Q ( 1 < ...

  2. Crisis of HDU(母函数)

    Crisis of HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. (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 ...

  4. 每日英语: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' ...

  5. bzoj1605 / P2905 [USACO08OPEN]农场危机Crisis on the Farm

    P2905 [USACO08OPEN]农场危机Crisis on the Farm 发现总步数$k<=30$,考虑用$k$瞎搞 设$f[u][i][j]$表示已经吹$u$次哨,全体奶牛向右走$i ...

  6. HDU 2110 Crisis of HDU

    Crisis of HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  7. 洛谷P2905 [USACO08OPEN]农场危机Crisis on the Farm

    P2905 [USACO08OPEN]农场危机Crisis on the Farm 题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每 ...

  8. UVa12186:Another Crisis(树形DP)

    一道简单的树形DP送给你. A couple of years ago, a new world wide crisis started, leaving many people with econo ...

  9. HDU 3749 Financial Crisis(点-双连通分量)

    Because of the financial crisis, a large number of enterprises go bankrupt. In addition to this, oth ...

  10. UVa 12186 Another Crisis

    题意: 给出一个树状关系图,公司里只有一个老板编号为0,其他人员从1开始编号.除了老板,每个人都有一个直接上司,没有下属的员工成为工人. 工人们想写一份加工资的请愿书,只有当不少于员工的所有下属的T% ...

随机推荐

  1. MYSQL存储过程中常使用的命令记录

    MYSQL存储过程中常使用的命令记录 1.触发器trigger 查看:show triggers; 2.存储过程procedure 查看:show procedure status; 查看详细:sho ...

  2. hdu 2486/2580 / poj 3922 A simple stone game 博弈论

    思路: 这就是K倍动态减法游戏,可以参考曹钦翔从“k倍动态减法游戏”出发探究一类组合游戏问题的论文. 首先k=1的时候,必败态是2^i,因为我们把数二进制分解后,拿掉最后一个1,那么会导致对方永远也取 ...

  3. hdu 1329 Hanoi Tower Troubles Again!

    找规律的题目an=an-1+(i+i%2)/2*2; ;}

  4. 【memcache缓存专题(2)】memcache安装与命令行使用

    进新公司一个多月了,一直没有时间来更新,后续还是要保持着每日更新的频率 安装 在windows上安装 略(都玩到缓存的程度了,就没必要在windows上捣弄了) 给个参考: http://blog.c ...

  5. 【nginx运维基础(4)】Nginx的日志管理(日志格式与定时分割日志)

    Nginx日志主要分为两种:访问日志和错误日志.日志开关在Nginx配置文件(一般在server段来配置)中设置,两种日志都可以选择性关闭,默认都是打开的. 访问日志access_log #日志格式设 ...

  6. 理解maven

    1.理解“仓库” 首次运行完mvn -version后,会在用户目录下创建一个.m2的目录(比如:C:\Users\当前用户名\.m2\),这个目录是maven的“本地仓库”,仓库是maven中一个很 ...

  7. unigui判断浏览器内核、操作系统以及是否移动终端函数

    function GetDeviceType(var OsName, BrowserName: string; var IsMobileDevice: Boolean): string; var I: ...

  8. asp.net(C#)读取word 文档的方法

    第一种方法 Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "Application/msw ...

  9. 231. Power of Two

    题目: Given an integer, write a function to determine if it is a power of two. 链接: http://leetcode.com ...

  10. Retrofit所有知识场景汇总

    https://futurestud.io/blog/retrofit-getting-started-and-android-client Retrofit Series Overview Gett ...