|Hdu 1561|动态规划|The more, The Better
来源:互联网 发布:windows arp命令事例 编辑:程序博客网 时间:2024/06/03 16:09
http://acm.hdu.edu.cn/showproblem.php?pid=1561
此题与选课一题一样,讲解看
http://blog.csdn.net/Darost/article/details/52555114
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#define ms(i,j) memset(i, j, sizeof(i));using namespace std;int n,m;int c[205];vector<int> G[205];int f[205][205];int t;void dfs(int u){for (int i=1;i<=m;i++)f[u][i] = c[u];for (int i=0;i<G[u].size();i++){int v = G[u][i];dfs(v);for (int j=t;j>=2;j--)for (int k=1;k<j;k++)f[u][j] = max(f[u][j], f[u][j-k]+f[v][k]);}}int main(){while (scanf("%d%d", &n, &m)==2&&(n||m)){for (int i=0;i<=n;i++) G[i].clear();ms(f,0); for (int i=1;i<=n;i++){int ai;scanf("%d%d", &ai, &c[i]);G[ai].push_back(i);}t = m+1;dfs(0);printf("%d\n", f[0][m+1]);} return 0;}
0 0
- |Hdu 1561|动态规划|The more, The Better
- hdoj(hdu)-1561-the more the better
- hdu 1561 The more,The better
- hdu 1561 the more,the better
- Hdu 1561 The more, The Better
- HDU 1561 The more, The Better
- HDU 1561 The more, The Better
- HDU-1561-The more, The Better
- HDU 1561 The more, The Better
- HDU 1561 The more, The Better
- HDU:1561 The more,The Better
- HDU 1561 The more, The Better
- hdu 1561 The more, The Better
- HDU 1561 The more ,The Better
- hdu 1561 The more, The Better DP
- HDU 1561 The more, The Better
- hdu 1561 The more, The Better
- HDU 1561 The more, The Better
- PCL输入输出
- Android中的线程与线程池
- Android Service非常全面的解析
- 微信公共号(企业号)开发框架-gochat的从零开始教程(二): 5分钟快速搭建自己的公共号
- 单词2016.9.16
- |Hdu 1561|动态规划|The more, The Better
- 127.自己开发一个 PHP 框架
- arp是什么协议,简述其在tcp/ip协议栈中的主要作用
- android studio 导入、移除module、以及加载module中的jar包
- react中的state
- 【神经网络与深度学习】【Qt开发】【VS开发】从caffe-windows-visual studio2013到Qt5.7使用caffemodel进行分类的移植过程
- 0916总结
- Aptana :调试 javascript 图解
- curl 和 wget 抓取网页