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. [转]C#鼠标拖动任意控件

    C#鼠标拖动任意控件(winform) 分类: c#2011-08-15 22:51 178人阅读 评论(0) 收藏 举报 winformc#userwindowsobjectapi using Sy ...

  2. 关于wp数据备份

    差点忘记记录,之前一直用wp数据备份,但是一直发送邮件不成功,后来才发现,原来是因为发送的邮箱没有设置开通那个什么pop鬼的,不记得叫什么了,看下图. 开通这个服务,就可以正常接收wp的数据邮件备份了 ...

  3. win10的坑之wifi找不到

    安装了win10一周以来,win10的坑太多太多,微软搞什么pc/mobile二合一,真是脑残行为. 首先是usb设备无缘无故找不到,据说是和杀毒软件/防火墙有关,后来是关掉了windows defe ...

  4. PreApplicationStartMethodAttribute的使用

    先预备一个类,用于Start时调用 public static class MyPreApplicationStart { public static void RegisterGlobalFilte ...

  5. 可怕的SCN!(转载)

    一.什么是SCNSCN(System Change Number 简称 SCN)是当Oracle数据库更新后,由DBMS自动维护去累积递增的一个数字.在Oracle中,有四种SCN,分别为:系统检查点 ...

  6. oracle 所有 hint(转)

    oracle 10g 有64个hints , 11g 增加到71 个, 下表中红色的代表已经过时的, 粗体的是11g 新增. Optimization Goals and Approaches (2) ...

  7. Linux操作系统,服务器端的主流

    1.无意之间,一直使用的Windows,其实也是在Unix的基础之上开发的,什么xp,win7等都是,就是Unix的一些堆砌,其实这样说也不对.但是windows的复杂程度比Linux要复杂,因为Wi ...

  8. python学习之----异常处理小示例

    网络是十分复杂的.网页数据格式不友好,网站服务器宕机,目标数据的标签找不到,都 是很麻烦的事情.网络数据采集最痛苦的遭遇之一,就是爬虫运行的时候你洗洗睡了,梦 想着明天一早数据就都会采集好放在数据库里 ...

  9. Servlet、Servlet容器等内容讲解

    转载自http://blog.csdn.net/iAm333 对于Servlet.Servlet容器以及一个Servlet容器-Tomcat这些概念讲解的挺清晰的,转载下 之前在开源中国看到一篇文章& ...

  10. XCode iOS Simulator 模拟器

    XCode7.3下,默认带了iOS 9.3 Simulator,iOS 8.4 Simulator总是安装不成功. mac os X,里的模拟器,全屏 ,windows win键+1/2/3 切换全屏 ...