HDU 1561(树形dp)
来源:互联网 发布:软件开发部门ios 编辑:程序博客网 时间:2024/05/20 09:47
#include<cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>#include<iostream>using namespace std;int dp[210][210];vector<int> list[210];int N, M;void dfs(int father){ for (decltype(list[father].size())i = 0; i <list[father].size(); i++) { int child = list[father][i]; if (list[child].size() > 0) { dfs(child); } for (int j = M; j >=2; j--) { for (int k =1; k < j; k++) { dp[father][j] = max(dp[father][j], dp[father][k] + dp[child][j - k]); } } }}int main(){ while (scanf("%d%d",&N,&M), N + M) { M++; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= N; i++) { int a, b; cin >> a >> b; list[a].push_back(i); for (int j = 1; j <= M; j++) { dp[i][j] = b; } } dfs(0); for (int i = 0; i <= N; i++) { list[i].clear(); } cout << dp[0][M] << endl; } return 0;}
0 0
- hdu 1561(树形DP)
- HDU 1561(树形dp)
- HDU 1561(树形DP)
- hdu 1561 树形DP
- hdu 1561(树形dp)
- hdu 1561 树形dp
- hdu 1561 树形dp
- HDU 1561 树形DP
- hdu 1561 树形dp
- hdu 1561 (树形dp+依赖背包)
- hdu 1561(树形dp)(背包dp)
- hdu 1561 简单树形dp
- HDU 1561 树形dp+背包
- hdu 1561简易树形DP
- hdu 1011(树形DP)
- (树形dp) hdu 1520
- HDU 1520(树形dp)
- HDU 1011(树形dp)
- Python 报错IndentationError: unindent does not match any outer indentation level
- java实现快速排序
- jstl标签的用法(一)
- iOS8之后UIAlertView被弃用 UIAlertController成功上位
- js 窗口操作
- HDU 1561(树形dp)
- eclipse启动项目非常慢
- poj 2455 Secret Milking Machine (网络流)
- 找连续数 HDU5247
- leetcode Construct Binary Tree from Inorder and Postorder Traversal
- redis基本命令
- android适配
- 归并排序
- tcp服务器与客户端