博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
例题9-12 UVa12186 Another Crisis(树型DP)
阅读量:7045 次
发布时间:2019-06-28

本文共 933 字,大约阅读时间需要 3 分钟。

题意:

看白书

要点:

白书上写的还是很清楚的,通过递归进行动态规划,vector还真是好用,暑假的时候学一下。

#include
#include
#include
#include
#include
#define maxn 100005using namespace std;int n, T;vector
son[maxn];int dp(int x){ if (son[x].empty()) return 1; int k = son[x].size(); vector
d; for (int i = 0; i < k; i++) d.push_back(dp(son[x][i]));//d表示x的子结点需要的工人签字数 sort(d.begin(), d.end()); int ans = 0; int c = (k*T-1)/100 + 1; //消除浮点误差 for (int i = 0; i < c; i++)//每次找它的前c个 ans += d[i]; return ans;}int main(){ int x; while (scanf("%d%d",&n,&T)==2) { if (n == 0 && T == 0) break; for (int i = 0; i <= maxn; i++)//每次都要清空vector数组 son[i].clear(); for (int i = 1; i <= n; i++) { scanf("%d", &x); son[x].push_back(i);//son[i]为结点i的子节点列表 } printf("%d\n", dp(0)); } return 0;}

转载于:https://www.cnblogs.com/seasonal/p/10343731.html

你可能感兴趣的文章
单元测试Struts2的Action(包含源码)
查看>>
简要总结最近遇到的5个问题
查看>>
我的友情链接
查看>>
高校专业机房使用VMware Player解决方案
查看>>
我的友情链接
查看>>
Centos Development Tools 安装
查看>>
1.1.2 C++发展历程
查看>>
我的友情链接
查看>>
awk笔记
查看>>
apache使用.htaccess进行基于文件扩展名的访问控制
查看>>
Hystrix降级技术解析-Fallback
查看>>
Windows XP 禁用防火墙、系统升级、系统还原指南
查看>>
让你的电脑变成wifi
查看>>
xshell 隧道透传
查看>>
zabbix-server添加zabbix-proxy
查看>>
iostat命令找不到
查看>>
外观模式
查看>>
我的友情链接
查看>>
Angular2 AoT编译以及Rollup摇树优化
查看>>
ReactJS 学习资料汇总
查看>>