Partial Tree

http://acm.hdu.edu.cn/showproblem.php?pid=5534

Time Limit: / MS (Java/Others)    Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): Problem Description
In mathematics, and more specifically in graph theory, a tree is an undirected graph in which any two nodes are connected by exactly one path. In other words, any connected graph without simple cycles is a tree. You find a partial tree on the way home. This tree has n nodes but lacks of n− edges. You want to complete this tree by adding n− edges. There must be exactly one path between any two nodes after adding. As you know, there are nn− 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? Input
The first line contains an integer T indicating the total number of test cases.
Each test case starts with an integer n in one line,
then one line with n− integers f(),f(),…,f(n−). ≤T≤
≤n≤
≤f(i)≤
There are at most test cases with n>. Output
For each test case, please output the maximum coolness of the completed tree in one line. Sample Input Sample Output Source
2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大) Recommend
hujie

因为每个点最少的度数为1,所以可以先设每个点的度数为1,剩余的度数为(2*n-2)-n=n-2,相当于把剩下的n-2个度分给n个顶点,这样就转化为完全背包的题目了

 #include<bits/stdc++.h>
const int INF=0x3f3f3f3f;
using namespace std; int a[];
int dp[]; int main(){ int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
int ans=a[]*n;
for(int i=;i<=n;i++) dp[i]=-INF;
dp[]=;
for(int i=;i<n;i++) a[i]-=a[];
for(int i=;i<n;i++){
for(int j=;j<=n-;j++){
dp[i+j-]=max(dp[i+j-],dp[j]+a[i]);
}
}
printf("%d\n",ans+dp[n-]);
} }

Partial Tree(DP)的更多相关文章

  1. HDU 5534/ 2015长春区域H.Partial Tree DP

    Partial Tree Problem Description In mathematics, and more specifically in graph theory, a tree is an ...

  2. hdu 5534 Partial Tree 背包DP

    Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  3. hdu 5534 (完全背包) Partial Tree

    题目:这里 题意: 感觉并不能表达清楚题意,所以 Problem Description In mathematics, and more specifically in graph theory, ...

  4. 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree

    Partial Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  5. HDU 5534 Partial Tree 完全背包

    一棵树一共有2*(n-1)度,现在的任务就是将这些度分配到n个节点,使这n个节点的权值和最大. 思路:因为这是一棵树,所以每个节点的度数都是大于1的,所以事先给每个节点分配一度,答案 ans=f[1] ...

  6. Partial Tree

    Partial Tree 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 完全背包 做这题前去学习了下完全背包,觉得这个优化简直神技!(以前都是 ...

  7. H - Partial Tree HDU - 5534 (背包)

    题目链接: H - Partial Tree  HDU - 5534 题目大意:首先是T组测试样例,然后n个点,然后给你度数分别为(1~n-1)对应的不同的权值,然后问你在这些点形成树的前提下的所能形 ...

  8. HDU - 5534 Partial Tree(每种都装的完全背包)

    Partial Tree In mathematics, and more specifically in graph theory, a tree is an undirected graph in ...

  9. hdu5534 Partial Tree

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submissi ...

随机推荐

  1. Find substring with K-1 distinct characters

    参考 Find substring with K distinct characters Find substring with K distinct characters(http://www.cn ...

  2. Linux性能分析 vmstat输出

    vmstat输出     1.linux系统下vmstat输出   vmstat的输出分为以下几种模式:   (1).VM MODE (普通选项) (2).DISK MODE(-d选项) (3).DI ...

  3. freemarker ,DEFAULT_INCOMPATIBLE_IMPROVEMENTS 找不到

    一般出现这种问题的原因是,spring的版本和freemarker不匹配造成的~ nested exception is org.springframework.beans.factory.BeanC ...

  4. mysql 字符集排查

    mysql 字符集排查 库级别 SELECT * FROM information_schema.schemata WHERE schema_name NOT IN ( 'information_sc ...

  5. BI开发(ETL-DW)

    来到公司已经参与开发了一段时间的BI项目,但是仅仅是按照需求开发,今天下午公司给大家培训数据仓库的知识,老大(女程序员)在上面讲,我们在下面听,2到3个小时吧,什么纬度,主题,几乎听的一脸茫然,最后演 ...

  6. php while循环控制实例讲解

    while循环是PHP中最简单的循环,其基本格式为: while (expr){ statement } 或者 while (expr): statement endwhile; 该语法表示,只要ex ...

  7. JavaScript中‘==’和'==='的区别

    javascript中,两个等号‘==’和三个等号‘===’的区别: 简单说,‘===’比‘==’对相等的概念更为严格,使用‘==’时,数字 1 和 字符串 “1” 是相等的: 而使用‘===’时,数 ...

  8. MyBatis 中#与$的区别

    今天在工作中有个点击排序的功能调试了许久,终寻因,总结之.  需求是这样的,页面有个table,有一列的上下箭头可点击并排序.对于这种需求,我的mybatis.xml的sql配置写成了如下: < ...

  9. VB ListView罗列图片

      一开始听到job的要求,还真不知道如何下手,用Gridview?好像有做不到把图片show出来的.在网上搜索一遍,发现原来是ListView与Imglist的结合应用. 看设计: Private ...

  10. python3中的mysql数据库操作

    软硬件环境 OS X EI Capitan Python 3.5.1 mysql 5.6 前言 在开发中经常涉及到数据库的使用,而python对于数据库也有多种解决方法.本文以python3中的mys ...