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 ...
随机推荐
- ofo走出校园观察:市场定位导致产品错位?
Ofo和摩拜单车虽然同样都是做单车共享,但实际上两者在最初的市场定位是有明显的差异的,因此提供的产品方案也存在巨大的差异. 市场定位不同,导致产品方案的巨大差异 摩拜单车一开始就定位于开放市场,充分的 ...
- 资料推荐--Google Java编码规范
之前已经推荐过Google的Java编码规范英文版了: http://google-styleguide.googlecode.com/svn/trunk/javaguide.html 虽然这篇文章的 ...
- 第三次个人作业——软件产品评测(K米Android端)
第一部分 调研,评测 1.K米简介 K米点歌是一款免费的社交K歌手机应用,其手机点歌功能主要在KTV.夜总会,酒吧等K歌场所中使用,当前提供iPhone版本及安卓版本下载使用. 2.评测 2.1.上手 ...
- Struts2-----面试题汇总
1.struts2框架中,从用户发出请求到获得响应整个过程的流转图 FilterDispatcher --> ActionProxy-->Configuration Manager--&g ...
- VGA 视频输出
VGA Video Output by Nathan Ickes Introduction VGA is a high-resolution video standard used mostly fo ...
- Spring MVC学习笔记——用户增删该查和服务器端验证
建立一个动态web项目,起名为SpringMVC_crud 导包,其中包括jstl的一些包等 1.先写一个User.java,是用户类 文件User.java文件 package org.common ...
- Java观察者设计模式
在java.util包中提供了Observable类和Observer接口,使用它们即可完成观察者模式. 多个观察者都在关注着价格的变化,只要价格一有变化,则所有的观察者会立即有所行动. //==== ...
- Android学习笔记——menu
该工程的功能是实现两个数相乘,并在另外一个Activity中显示计算的结果 以下的代码是MainActivity.java中的代码 package com.example.menu; import a ...
- UVa 11988 Broken Keyboard(链表->数组实现)
/*数组形式描述链表:链表不一定要用指针. 题目链接:UVa 11988 Broken Keyboard 题目大意: 小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 home end ...
- CodeForces 710A King Moves(水题-越界问题)
题目链接:http://codeforces.com/problemset/problem/710/A 题目大意:在一个棋盘中给出一个位置,判断该位置周围8个点还有几个点可以摆放棋子. AC代码解释解 ...