uva 12186 - Another Crisis-树上动态规划
来源:互联网 发布:大数据时代的教育 编辑:程序博客网 时间:2024/05/22 12:35
// uva 12186 - Another Crisis-树上动态规划/* 典型的树形动态规划问题: 此题题目意思很简单,也很好想到解法,但是就是写程序需要注意。 设d[i]表示以节点i为向上级提交申请需要工人签字的人数。 那么对于节点i,d[i] 是节点i子节点 d[j]集合的最小的前c个值,c为满足直属下属签字率至少为T时签字的人数。 在计算时我们采用了递归的方式。还有就是这提议为啥 不用记忆化搜索呢,因为一个节点最多访问一次,所以没有必要记忆化。 */#include <iostream>#include <queue>#include <stack>#include <stdio.h>#include <stdlib.h>#include <math.h>#include<vector>#include <string.h>#include <algorithm>#include <set>#include <map>#include <cstdio>#define ll long longusing namespace std ;int d[500000 + 10] ;vector<int> son[500000+10] ;int T , n ;int dp(int u ){ if(son[u].size() == 0 ) return 1 ; int len = (int)son[u].size() ; vector<int> temp ;temp.clear() ; for (int i = 0 ; i < len ; i++) { temp.push_back(dp(son[u][i])) ; } sort(temp.begin() , temp.end()) ; int c = (len * T - 1)/100 + 1 ; int ans = 0 ; for (int i = 0; i < c ; i++) { ans += temp[i] ; } return ans ;}int main(int argc, const char * argv[]) { int d ; while(scanf("%d%d" ,&n,&T)==2 &&n+T){ for(int i = 0 ; i < n + 1 ; i++) son[i].clear() ; for (int i = 0; i < n; i++) { scanf("%d" ,&d) ; son[d].push_back(i+1) ; } printf("%d\n" , dp(0)) ; } return 0;}
0 0
- uva 12186 - Another Crisis-树上动态规划
- 【UVA】12186-Another Crisis(动态规划)
- UVa 12186 Another Crisis dp:树上dp
- Uva-12186-Another Crisis
- UVA 12186 Another Crisis
- UVA - 12186 Another Crisis
- UVA-12186 Another Crisis
- uva 12186 Another Crisis
- UVA 12186 Another Crisis
- UVA 12186 Another Crisis
- UVA 12186(p282)----Another Crisis
- UVa OJ 12186 - Another Crisis
- UVA 12186 - Another Crisis(树形DP)
- Another Crisis - UVa 12186 树形dp
- UVA 12186 Another Crisis(树形DP)
- UVa 12186 Another Crisis(树形DP)
- UVA 12186 Another Crisis 树形DP
- UVa #12186 Another Crisis (例题9-12)
- 单链表反转
- java学习_集合(2)
- 使用cocoapods 安装第三方框架报错target overrides the `OTHER_LDFLAGS`。。的解决方案
- HDU5493 Queue【线段树】
- JAVA基础--db21_java网络编程&序列化
- uva 12186 - Another Crisis-树上动态规划
- 思维盛宴之设计模式-适配器模式Adapter Pattern
- spring 事务注解
- ScrollView分析 (2012-11-12 19:30:51)
- java线程池学习(二) —— 实现一个简单的线程池
- 排除特定的内容
- 软件工程之需求分析
- hdu 5489 Removed Interval 动态规划,最长上升子序列
- LintCode 合并排序数组 II