ZOJ 3201 Tree of Tree
Tree of Tree
Time Limit: 1 Second Memory Limit: 32768 KB
You're given a tree with weights of each node, you need to find the maximum subtree of specified size of this tree.
Tree Definition
A tree is a connected graph which contains no cycles.
Input
There are several test cases 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 nonnegative integers, where the k-th integer indicates the weight of k-th node. The following N - 1 lines describe the tree, each line are two integers which means there is an edge between these two nodes. All indices above are zero-base and it is guaranteed that the description of the tree is correct.
Output
One line with a single integer for each case, which is the total weights of the maximum subtree.
Sample Input
3 1
10 20 30
0 1
0 2
3 2
10 20 30
0 1
0 2
Sample Output
30
40
Author: LIU, Yaoting
|
#include <iostream>
#include <cstdio> #include <cstring> #include <vector> using namespace std; int dp[200][200],valu[200],cnt[200],ans,N,K; int dfs(int u,int fa) int main() |
* This source code was highlighted by YcdoiT. ( style: Emacs )
ZOJ 3201 Tree of Tree的更多相关文章
- ZOJ 3201
id=15737" target="_blank">Tree of Tree Time Limit: 1000MS Memory Limit: 32768KB ...
- LEETCODE —— binary tree [Same Tree] && [Maximum Depth of Binary Tree]
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
- B-tree/B+tree/B*tree [转]
(原文出处:http://blog.csdn.net/hbhhww/article/details/8206846) B~树 1.前言: 动态查找树主要有:二叉查找树(Binary Search Tr ...
- leetcode面试准备:Lowest Common Ancestor of a Binary Search Tree & Binary Tree
leetcode面试准备:Lowest Common Ancestor of a Binary Search Tree & Binary Tree 1 题目 Binary Search Tre ...
- [BZOJ3080]Minimum Variance Spanning Tree/[BZOJ3754]Tree之最小方差树
[BZOJ3080]Minimum Variance Spanning Tree/[BZOJ3754]Tree之最小方差树 题目大意: 给定一个\(n(n\le50)\)个点,\(m(m\le1000 ...
- easyui tree扩展tree方法获取目标节点的一级子节点
Easyui tree扩展tree方法获取目标节点的一级子节点 /* 只返回目标节点的第一级子节点,具体的用法和getChildren方法是一样的 */ $.extend($.fn.tree.meth ...
- Tree - Decision Tree with sklearn source code
After talking about Information theory, now let's come to one of its application - Decision Tree! No ...
- Binary Indexed Tree (Fenwick Tree)
Binary Indexed Tree 主要是为了存储数组前缀或或后缀和,以便计算任意一段的和.其优势在于可以常数时间处理更新(如果不需要更新直接用一个数组存储所有前缀/后缀和即可).空间复杂度O(n ...
- POJ1741 Tree + BZOJ1468 Tree 【点分治】
POJ1741 Tree + BZOJ1468 Tree Description Give a tree with n vertices,each edge has a length(positive ...
随机推荐
- soapUI测试webservice(参数为xml格式的处理方式)
如果传递的是xml,要用<![CDATA[ ]]>将xml注释为字符串 示例 <?xml version="1.0" encoding="UTF-8 ...
- 加州大学伯克利分校Stat2.3x Inference 统计推断学习笔记: Section 3 One-sample and two-sample tests
Stat2.3x Inference(统计推断)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授. PDF笔记下载(Acad ...
- HDU 1598 find the most comfortable road(最小生成树之Kruskal)
题目链接: 传送门 find the most comfortable road Time Limit: 1000MS Memory Limit: 32768 K Description XX ...
- Pyhton 单行、多行注释符号使用方法及规范
一.单行注释符号 # 用作单行注释符号. print 1 #输出1 二.多行注释符号 多行注释是用三引号''' '''包含. ''' 用于解析所有从网页上保存下来的页面(html) ...
- SOA 和webservice 的区别
http://blog.csdn.net/bingjing12345/article/details/7575566 Web service 的具体过程 需要明确的东西 1, 服务器端 和 客户端 之 ...
- break; continue; goto; return在循环中的应用
1. break表示跳出循环,程序指向循环体后的第一条语句: ; ) { ) break; console.writeline("{0}",i++); } console.read ...
- Linux开放1521端口允许网络连接Oracle Listene
症状:1. TCP/IP连接是通的.可以用ping 命令测试. 2. 服务器上Oracle Listener已经启动. lsnrctl status 查看listener状态 lsnrctl s ...
- OpenGL Registry
https://www.opengl.org/registry/ https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api ...
- 单点登录(SSO)系统的总结
前些天一位其他开发部门的同事找到我们了解一些关于SSO单点登录的事,他们要做单点登录,同时也需要和我们这边的系统做集成,要我帮忙做一单点登录,了解关于单点登录的解决方案和资料,虽然做单点登录已经很久了 ...
- HTML5 Web Form 新增属性和表单验证
<form>标签的基本属性 method属性:指定浏览器向服务器传送数据的方式,可选: action属性:设置服务器接受和处理表单数据的URL: enctype属性:制定表单数据在发送到服 ...