POJ 2486 Apple Tree
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6411 | Accepted: 2097 |
Description
Input
Each test case contains three parts.
The first part is two numbers N K, whose meanings we have talked about just now. We denote the nodes by 1 2 ... N. Since it is a tree, each node can reach any other in only one route. (1<=N<=100, 0<=K<=200)
The second part contains N integers (All integers are nonnegative and not bigger than 1000). The ith number is the amount of apples in Node i.
The third part contains N-1 line. There are two numbers A,B in each line, meaning that Node A and Node B are adjacent.
Input will be ended by the end of file.
Note: Wshxzt starts at Node 1.
Output
Sample Input
1 3Sample Output
11
2
Source
|
#include <iostream>
#include <cstdio> #include <cstring> #include <vector> using namespace std; vector<int> g[200]; void Tree_Dp(int s) int main() |
* This source code was highlighted by YcdoiT. ( style: Codeblocks )
POJ 2486 Apple Tree的更多相关文章
- poj 2486 Apple Tree(树形DP 状态方程有点难想)
Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9808 Accepted: 3260 Descri ...
- POJ 2486 Apple Tree(树形dp)
http://poj.org/problem?id=2486 题意: 有n个点,每个点有一个权值,从1出发,走k步,最多能获得多少权值.(每个点只能获得一次) 思路: 从1点开始,往下dfs,对于每个 ...
- POJ 2486 Apple Tree ( 树型DP )
#include <iostream> #include <cstring> #include <deque> using namespace std; #defi ...
- POJ 2486 Apple Tree(树形DP)
题目链接 树形DP很弱啊,开始看题,觉得貌似挺简单的,然后发现貌似还可以往回走...然后就不知道怎么做了... 看看了题解http://www.cnblogs.com/wuyiqi/archive/2 ...
- poj 2486 Apple Tree (树形背包dp)
本文出自 http://blog.csdn.net/shuangde800 题目链接: poj-2486 题意 给一个n个节点的树,节点编号为1~n, 根节点为1, 每个节点有一个权值. 从 ...
- POJ 2486 Apple Tree [树状DP]
题目:一棵树,每个结点上都有一些苹果,且相邻两个结点间的距离为1.一个人从根节点(编号为1)开始走,一共可以走k步,问最多可以吃多少苹果. 思路:这里给出数组的定义: dp[0][x][j] 为从结点 ...
- POJ 2486 Apple Tree (树形DP,树形背包)
题意:给定一棵树图,一个人从点s出发,只能走K步,每个点都有一定数量的苹果,要求收集尽量多的苹果,输出最多苹果数. 思路: 既然是树,而且有限制k步,那么树形DP正好. 考虑1个点的情况:(1)可能在 ...
- POJ 2486 Apple Tree (树形dp 经典题)
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const ...
- POJ 2486 Apple Tree ——(树型DP)
题意是给出一棵树,每个点都有一个权值,从1开始,最多走k步,问能够经过的所有的点的权值和最大是多少(每个点的权值只能被累加一次). 考虑到一个点可以经过多次,设dp状态为dp[i][j][k],i表示 ...
随机推荐
- Web 使用PostMan提交特殊格式数据
使用PostMan 选择POST模式中的RAW模式 然后点击Headers添加Content-Type 类型比如是 application/json 然后就可以在body中以Json格式上传数据了 前 ...
- 关于git不区分文件名大小写的处理
今天遇到了git不区分文件名大小写的问题,一开始着实郁闷了一把. 处理办法: windows下在git中修改文件的大小写 git mv --force myfile MyFile 或者 git mv ...
- hihoCoder #1164 随机斐波那契
时间限制:5000ms单点时限:1000ms内存限制:256MB描述 大家对斐波那契数列想必都很熟悉: $a_0 = 1, a_1 = 1, a_i = a_{i-1} + a_{i-2}, (i & ...
- canvas练习
<!doctype html><html><head><meta charset="utf-8"><title>move ...
- 匿名函数:Lambda表达式和匿名方法
匿名函数一个"内联"语句或表达式,可在需要委托类型的任何地方使用.可以使用匿名函数来初始化命名委托,或传递命名委托(而不是命名委托类型)作为方法参数. 共有两种匿名函数: Lamb ...
- matlab连接sql数据库
最近项目还涉及到matlab连接数据库,下面我就记录如何进行配置使得matlab能够连接sql数据库.由于最近工程做的多一些,所以分享的都在工程配置上,当初为了这些配置可是反复卸载与重装,算法其实也有 ...
- c#多态之抽象类与接口的一点收获~~
多态之抽象类与接口的相似点及不同点,刚学习的一点收获,或许不是很完整,借鉴看视频及一些被人写的文章自己写的下的一些心得!以便之久复习使用! 一.抽象类 (1) 抽象方法只作声明,而不包含实现,可以看成 ...
- Java Web的两种开发模式
参考文献:http://www.cnblogs.com/xdp-gacl/p/3908610.html 一.Jsp+JavaBean 此模式如下图所示:
- QT 初阶 1.3 节 控件的几何排列
#include "mainwindow.h" #include <QApplication> #include <QHBoxLayout> #includ ...
- jar tvf study.war jar命令查看war/jar包的内容
jar tvf study.war 0 Thu Oct 20 14:01:18 CST 2016 META-INF/ 137 Thu Oct 20 14:01:16 CST 2016 META-INF ...