HDU 5534 完全背包
Partial Tree
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 823 Accepted Submission(s): 407
You find a partial tree on the way home. This tree has n nodes but lacks of n−1 edges. You want to complete this tree by adding n−1 edges. There must be exactly one path between any two nodes after adding. As you know, there are nn−2 ways to complete this tree, and you want to make the completed tree as cool as possible. The coolness of a tree is the sum of coolness of its nodes. The coolness of a node is f(d), where f is a predefined function and d is the degree of this node. What's the maximum coolness of the completed tree?
Each test case starts with an integer n in one line,
then one line with n−1 integers f(1),f(2),…,f(n−1).
1≤T≤2015
2≤n≤2015
0≤f(i)≤10000
There are at most 10 test cases with n>100.
3
2 1
4
5 1 4
19
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = ;
const int inf = 0x3f3f3f3f;
int f[maxn];
int dp[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
int ans = ;
scanf("%d",&n);
for(int i = ; i<n; i++) scanf("%d",&f[i]);
ans = n*f[];
for(int i = n-; i>; i--) f[i] -= f[];
for(int i = ; i<=n-; i++)
dp[i] = -inf;
dp[] = ;
for(int i = ; i <= n-; i++) //因为1度已定,所以从2枚举度数
for(int j = ; j <= n-; j++)
if(j>=i-) dp[j] = max(dp[j],dp[j-i+]+f[i]);
printf("%d\n",ans+dp[n-]);
}
return ;
}
HDU 5534 完全背包的更多相关文章
- hdu 5534 (完全背包) Partial Tree
题目:这里 题意: 感觉并不能表达清楚题意,所以 Problem Description In mathematics, and more specifically in graph theory, ...
- H - Partial Tree HDU - 5534 (背包)
题目链接: H - Partial Tree HDU - 5534 题目大意:首先是T组测试样例,然后n个点,然后给你度数分别为(1~n-1)对应的不同的权值,然后问你在这些点形成树的前提下的所能形 ...
- HDU 1011 树形背包(DP) Starship Troopers
题目链接: HDU 1011 树形背包(DP) Starship Troopers 题意: 地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...
- hdu 5445 多重背包
Food Problem Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)To ...
- hdu 1203 01背包 I need a offer
hdu 1203 01背包 I need a offer 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 题目大意:给你每个学校得到offe ...
- HDU 5534 Partial Tree (完全背包变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题意: 给你度为1 ~ n - 1节点的权值,让你构造一棵树,使其权值和最大. 思路: 一棵树上 ...
- hdu 5534 Partial Tree 背包DP
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- hdu 5534 Partial Tree(完全背包)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5534 题解:这题一看有点像树形dp但是树形dp显然没什么思路.然后由于这里的约束几乎没有就 ...
- HDU 5534 Partial Tree 完全背包
一棵树一共有2*(n-1)度,现在的任务就是将这些度分配到n个节点,使这n个节点的权值和最大. 思路:因为这是一棵树,所以每个节点的度数都是大于1的,所以事先给每个节点分配一度,答案 ans=f[1] ...
随机推荐
- hdu_2110_Crisis of HDU(母函数)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2110 题意:给你N个价值和数目,求方案数,很裸的母函数. #include<cstdio> ...
- override the hashcode and equals method in java
http://howtodoinjava.com/2012/10/09/working-with-hashcode-and-equals-methods-in-java/
- s7-300 第9讲 定时器
- Inno Setup入门(二十二)——Inno Setup类参考(8)
: Install Setup 2013-02-02 11:31 477人阅读 评论(0) 收藏 举报 列表框 列表框(ListBox)是Windows应用程序中重要的输入手段,其中包括多个选项用户可 ...
- Java学习笔记之多态
1.父类型的引用可以指向子类型的对象: Parent p = new Child(); 2.当使用多态方式调用方法时,首先检查父类中是否有该方法,如果没有,则编译错误:如果有,再去调用子类的该同名方法 ...
- idea 端口占用
netstat -anp | grep 8080 lsof -i:8080 查看8080端口被什么进程占用 kill (-s 9) 12903 -s 9 强制 尽快 12903 上面查出的 PID 其 ...
- JPA 系列教程8-双向一对一共享主键
双向一对一共享主键的ddl语句 CREATE TABLE `t_person` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `name` varchar(25 ...
- thinkphp中select()和find()的区别
find()返回一个一维数组 select()返回一个二维数组 所以在取值时有所不同,一维数组取值用$data["data"],二维数组取值用$data[0]["data ...
- Objective-C相关Category的收集
Objective-C相关Category的收集 Categories是给你得不到源码的classes增加功能的一种方法.这个页面收集一些相关的Category,并且持续更新,你可以订阅关注.作者是F ...
- Theos tweak MSHookFunction
#import "substrate.h" static FILE * (*s_orig_fopen) ( const char * filename, const char * ...