ACM:最大子树 动态规划题 toj2676
来源:互联网 发布:麻瓜编程 爬虫 编辑:程序博客网 时间:2024/06/05 14:04
Tree of Tree
描述
You're given a tree withweights of each node, you need to find the maximum subtree ofspecified size of this tree.
Tree Definition
A tree is a connected graph which contains no cycles.
输入
There are several testcases in the input.
The first line of each case are two integers N(1<= N <= 100), K(1 <= K<= N), where N is the number of nodes of this tree,and K is the subtree's size, followed by a line with N nonnegativeintegers, where the k-th integer indicates the weight of k-th node.The following N - 1 lines describe the tree, each line are twointegers which means there is an edge between these two nodes. Allindices above are zero-base and it is guaranteed that thedescription of the tree is correct.
输出
One line with a singleinteger for each case, which is the total weights of the maximumsubtree.
样例输入
3 1
10 20 30
0 1
0 2
3 2
10 20 30
0 1
0 2
样例输出
30
40
题意: 给你一棵树,每个节点有一个相应的权值. 并且给定确定的子树节点个数, 求出最大的子树.
解题思路:
代码:
#include<cstdio>
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
#define MAX 205
structnode
{
}edges[MAX];
int w[MAX],first[MAX];
int n, k;
int maxsize;
int num;
int dp[MAX][MAX];
inline intmax(int a,int b)
{
}
voidread_graph()
{
}
void find(intcurNode,int child)
{
}
void dfs(intcurNode,int parent)
{
}
intmain()
{
//
}
- ACM:最大子树 动态规划题 toj2676
- ACM: 动态规划题 toj1328
- ACM: 动态规划题 poj3280
- ACM: 简单动态规划题 poj 2955
- ACM: 动态规划题+剪枝 toj 3904
- ACM: 动态规划题 toj 1072
- ACM: 动态规划题 poj 2241
- ACM: 动态规划题 toj 1508
- ACM: 动态规划题 toj 1511
- ACM: 动态规划题 toj 1545
- ACM: 动态规划题 poj 1054
- ACM: 动态规划题 poj 2948
- ACM: 动态规划题 poj 1925
- ACM: 动态规划题 poj 3034
- ACM: 动态规划题 poj 2411
- ACM: 动态规划题 poj 1947
- ACM: 动态规划题 poj 2486
- ACM: 动态规划题 poj 3140
- 图论: 最小费用最大流
- ACM: spfa+dfs 图论题 poj 2679
- ACM: 简单最小生成树 图论题 poj 1…
- ACM: 序列中找最小逆序对 杂题 TOJ…
- ACM: 数论题 toj 1721
- ACM:最大子树 动态规划题 toj2676
- 虚拟机下安装ubuntu后root密码设置
- ACM: 数论题 toj3343 同 poj 1061
- ACM: 优先队列 数据结构题 toj 290…
- ACM: 变形的LCS(最长公共子序) toj…
- 动态规划: 航线设置 (求最大升序长…
- 动态规划: poj1505改编题
- 包装类
- ACM: 动态规划 poj 2479