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 ...
随机推荐
- TCP/IP详解 笔记十二
简单文件传送协议 TFTP 1) 初衷是为了引导无盘系统 2) 使用UDP 3) 代码都能适合只读存储器 无盘主机通过RARP获得ip地址后进行一个TF ...
- Unity 插件制作笔记(持续更新)
示例: [MenuItem(Menu1/Menu2)] static void TestMenu1() { Debug.log("点击了菜单"); } 导航菜单添加 [MenuIt ...
- 《JavaScript权威指南》学习笔记 第六天 开始学习DOM了。
昨天学习了window对象的一些方法.window对象主要是针对当前视窗的操作.window对象提供了一些列API来帮助我们了解当前窗口的信息.例如history对象可以让我们获取浏览历史.nvaig ...
- bootstrap学习总结-05 常用标签3
1 单选框,多选框 1)单选框 单选框(radio)用于从多个选项中只选择一个.设置了 disabled 属性的单选或多选框都能被赋予合适的样式.对于和多选或单选框联合使用的 <label> ...
- JDBC编程的方式
JDBC编程的方式,我们以一个简单的查询为例,使用JDBC编程,如下: 从上面可以看出JDBC编程一般要如下步骤: 1. 加载数据库驱动 2. 创建并获取数据库连接 3. 创建jdbc stateme ...
- 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099的解决办法
一.问题描述 今天一来公司,在IntelliJ IDEA 中启动Tomcat服务器时就出现了如下图所示的错误:
- js021-Ajax与Comet
js021-Ajax与Comet 本章内容: 使用XMLHttpRequet对象 使用XMLHttpRequet事件 跨域Ajax通信的限制 Ajax技术的核心是XMLHttpRequet对象 21. ...
- vim 使用总结
VIM分屏显示 1 . 水平分屏split(sp) || 垂直分屏vsplit(vs) :(v)split 输入这样的命令后vi就会将当前的窗口平分为两个,并且在这两个窗口中显示的是同一篇文章.如 ...
- 9月12日JavaScript脚本语言
JS脚本语言 JS脚本语言全称JavaScript,是网页里面使用的脚本语言,也是一门非常强大的语言. 一.基础语法 1.注释语法 单行注释:// 多行注释:/**/ 2.输出语法 ①alert(信息 ...
- 对二进制加密(分散保存-s=sy+a+b)
#include <stdio.h> #define L 40 void jiaM(int * s,int * a,int *b,int *sy); void jieM(int * a,i ...