Partial Tree(DP)
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)的更多相关文章
- HDU 5534/ 2015长春区域H.Partial Tree DP
Partial Tree Problem Description In mathematics, and more specifically in graph theory, a tree is an ...
- 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
题目:这里 题意: 感觉并不能表达清楚题意,所以 Problem Description In mathematics, and more specifically in graph theory, ...
- 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree
Partial Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- HDU 5534 Partial Tree 完全背包
一棵树一共有2*(n-1)度,现在的任务就是将这些度分配到n个节点,使这n个节点的权值和最大. 思路:因为这是一棵树,所以每个节点的度数都是大于1的,所以事先给每个节点分配一度,答案 ans=f[1] ...
- Partial Tree
Partial Tree 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 完全背包 做这题前去学习了下完全背包,觉得这个优化简直神技!(以前都是 ...
- H - Partial Tree HDU - 5534 (背包)
题目链接: H - Partial Tree HDU - 5534 题目大意:首先是T组测试样例,然后n个点,然后给你度数分别为(1~n-1)对应的不同的权值,然后问你在这些点形成树的前提下的所能形 ...
- HDU - 5534 Partial Tree(每种都装的完全背包)
Partial Tree In mathematics, and more specifically in graph theory, a tree is an undirected graph in ...
- hdu5534 Partial Tree
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submissi ...
随机推荐
- LBS(基于位置服务)
ylbtech-杂项:LBS(基于位置服务) 基于位置的服务,它是通过电信移动运营商的无线电通讯网络(如GSM网.CDMA网)或外部定位方式(如GPS)获取移动终端用户的位置信息(地理坐标,或大地坐标 ...
- BCGcontrolBar(一) MFC界面库简介
原帖地址:http://blog.csdn.net/zw514159799/article/details/9148385 英文原文:http://www.bcgsoft.com/bcgcontrol ...
- blktrace 深度了解linux系统的IO运作
http://blog.yufeng.info/archives/751 我们在Linux上总是要保存数据的,数据要么保存在文件系统里(如ext3),要么就在裸设备里面.我们在使用这些数据的时候都是通 ...
- Solr Facet 搜索时,facet.missing = true 的真正含义
Solr的WiKI原文是如下解释: facet.missing Set to "true" this param indicates that in addition to the ...
- ajaxGet 获取封装
callback 表示下一个功能(回调函数) function ajaxGet(url,callback,data){ 如果路径上有参数 就在url后面拼接参数 否则只请求url ...
- SignalR + Mvc 4 web 应用程序
在上节中,我们已经初步对 SignalR 进行了了解,这一节我们将做一个SignalR Demon,具体的步骤如下: 1. 创建一个 mvc 4 web 应用程序,并选择 Basic 2. 创建一个 ...
- python气象分析
数据分析实例 -- 气象数据 一.实验介绍 本实验将对意大利北部沿海地区的气象数据进行分析与可视化.我们在实验过程中先会运用 Python 中matplotlib库的对数据进行图表化处理,然后调用 s ...
- Using Celery with Django
参考1: http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#using-celery-with-d ...
- 更新403 Forbidden
用TidHTTP下载一个文件 http://192.168.1.1/files/新建文本文档.txt 报错,但是用浏览器打开正常 HTTP/1.1 403 Forbidden 最后不是程序的问题,把i ...
- 常用Sql语句,及注意事项
目录: sql语句 sql命令语句 关键字 sql语句 SELECT * FROM V$reserved_words;--查询oracle预留关键字 SELECT * FROM V$version;- ...