ZOJ 3201 Tree of Tree(树形dp + 分组背包)
来源:互联网 发布:零基础学算法百度云 编辑:程序博客网 时间:2024/05/16 14:59
OJ题目:click here ~~
AC_CODE
const int inf = 1<<30;int n , k;int x[102];int dp[102][102];vector < int > List[102];void dfs(int u , int father){ int i , j; for(i = 0;i < List[u].size();i++) { int v = List[u][i]; if(v == father) continue; dfs(v , u); for(j = k;j >= 1;j--)//一定要倒序 { for(int t = 1;t <= j;t++) dp[u][j] = max(dp[u][j] , dp[u][t] + dp[v][j - t]); } }}int main(){ while(cin >> n >> k) { int i , j , a , b; for(i = 0;i <= n;i++) List[i].clear(); memset(dp , 0 , sizeof(dp)); for(i = 0;i < n;i++) { scanf("%d",&dp[i][1]); } for(i = 0;i < n-1;i++) { scanf("%d%d",&a,&b); List[a].push_back(b); List[b].push_back(a); } dfs(0 , -1); int ans = -1; for(i = 0;i < n;i++) ans = max(ans , dp[i][k]); cout << ans << endl; } return 0;}
0 0
- ZOJ 3201 Tree of Tree(树形dp + 分组背包)
- ZOJ 3201 Tree of Tree(树形背包DP)
- zoj 3201 Tree of Tree(树形背包dp)
- ZOJ 3201 Tree of Tree(树形DP+背包)
- ZOJ 3201 Tree of Tree 树形DP
- ZOJ - 3201 Tree of Tree 树形DP
- zoj 3201 Tree of Tree 树形dp基础题——树形背包
- ZOJ 3201 Tree of Tree 大水树形背包
- 【树形dp】ZOJ-3326-Tree of Tree
- zoj 3201 简单树形dp Tree of Tree
- ZOJ 3201 Tree of Tree(树形DP)
- TOJ 2676 ZOJ 3201 Tree of Tree / 树形DP
- POJ 2486 Apple Tree 树形DP+分组背包
- ZOJ Monthly, July 2011 - G Tree of Three(树形DP)
- 树形DP专辑-ZOJ3201(Tree of Tree)
- ZOJ3201 Tree of Tree 【树形dp】
- (树形DP)tree of tree (zju)
- Zoj3201 Tree of Tree 树形DP
- ios scroll view 原理
- nginx configure location 流程以及重要函数分析
- Java输出指定图形--菱形
- Application Loader 上传中断后无法继续上传的解决方法
- 新劳动法并没有将公司的高管们纳入保护范围
- ZOJ 3201 Tree of Tree(树形dp + 分组背包)
- MFC基本常用控件基本用法
- 使用 JMeter 完成常用的压力测试
- MySQL 服务器调优
- Java NIO系列教程(二) Channel
- “另一阿里”的故事
- python读取json文件,并将数据插入到mongodb
- leetcode 第4题 Add Two Numbers
- 30岁,程序员伤不起的年龄