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表示 ...
随机推荐
- 数据结构算法C语言实现(六)---2.4一元多项式的表示及相加
一.简述 利用链表表示稀疏多项式,并基于之前的一些操作(编程实现上还是有所不同的)组合新的操作实现一元多项式的表示及相加. 二.ADT 抽象数据类型一元多项式的定义 ADT Polyomail{ 数据 ...
- C语言实现penna模型
一年前写的代码,偶然翻出来.发现自己当时水平还不赖吗. # include <stdio.h> # include <stdlib.h> # include <time. ...
- Java 中常用缓存Cache机制的实现
所谓缓存,就是将程序或系统经常要调用的对象存在内存中,一遍其使用时可以快速调用,不必再去创建新的重复的实例.这样做可以减少系统开销,提高系统效率. 所谓缓存,就是将程序或系统经常要调用的对象存在内存中 ...
- hihocoder #1327
传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个只包含小写字母'a'-'z'的字符串 S ,你需要将 S 中的字符重新排序,使得任意两个相同的字符不连在一 ...
- linux中配置NTP基本操作
计算机的系统时间是由计算机内的石英晶体震荡电路以固定的震荡频率产生的date 查看当前时区vim /etc/sysconfig/clock 修改时区配置文件ZONE="America/Ne ...
- 今天接触枚举类型,感觉是C里面应该才有的东西
遍历枚类型的方法: public static EActChannel getEnumByCode(int code) { for (EActChannel enm : EActChannel.val ...
- 【原】ajaxupload.js上传报错处理方法
相信大家在工作中经常用到文件上传的操作,因为我是搞前端的,所以这里主要是介绍ajax在前端中的操作.代码我省略的比较多,直接拿js那里的 $.ajaxFileUpload({ url:'www.cod ...
- js初学—js全自定义单选框
代码如下: <script type="text/javascript"> window.onload=function() { var oIput=document. ...
- 蛋疼的vs
这个vs2008 难用的很,要是叫我选肯定vs高版本的,vs2012或者直接vs2015
- ListBox
<asp:ListBox runat="server" ID="txtName" Width ="200" Height=" ...