hdu 5534 (完全背包) Partial Tree
题目:这里
题意:
感觉并不能表达清楚题意,所以
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<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; #define inf 0x3f3f3f3f
const int M = 1e4 + ;
int dp[M],a[M]; int max(int x,int y){return x>y?x:y;} int main()
{
int t,n;
scanf("%d",&t);
while (t--){
scanf("%d",&n);
for (int i= ; i<n ; i++) {
scanf("%d",&a[i]);
if (i!=) a[i]-=a[];
}
//int pa=n*2-2;
for (int i= ; i<=n ; i++) dp[i]=-inf;
dp[]=;//dp[1]=a[1];
for (int i= ; i<n ; i++) {
for (int j= ; j+i-<=n- ; j++)
dp[i+j-] = max(dp[i+j-],dp[j]+a[i]);
}
printf("%d\n",dp[n-]+n*a[]);
}
return ;
}
hdu 5534 (完全背包) Partial Tree的更多相关文章
- HDU 5534 完全背包
Partial Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- hdu 5534 Partial Tree 背包DP
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- H - Partial Tree HDU - 5534 (背包)
题目链接: H - Partial Tree HDU - 5534 题目大意:首先是T组测试样例,然后n个点,然后给你度数分别为(1~n-1)对应的不同的权值,然后问你在这些点形成树的前提下的所能形 ...
- HDU 5534 Partial Tree 完全背包
一棵树一共有2*(n-1)度,现在的任务就是将这些度分配到n个节点,使这n个节点的权值和最大. 思路:因为这是一棵树,所以每个节点的度数都是大于1的,所以事先给每个节点分配一度,答案 ans=f[1] ...
- HDU - 5534 Partial Tree(每种都装的完全背包)
Partial Tree In mathematics, and more specifically in graph theory, a tree is an undirected graph in ...
- HDU 5534/ 2015长春区域H.Partial Tree DP
Partial Tree Problem Description In mathematics, and more specifically in graph theory, a tree is an ...
- 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree
Partial Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- Partial Tree
Partial Tree 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 完全背包 做这题前去学习了下完全背包,觉得这个优化简直神技!(以前都是 ...
- Partial Tree(DP)
Partial Tree http://acm.hdu.edu.cn/showproblem.php?pid=5534 Time Limit: / MS (Java/Others) Memory Li ...
随机推荐
- 关于C#本质论和CLR via C#中译本,不吐不快
C#本质论和CLR via C#两本好书,周老师可能是俗务缠身,太忙了吧,翻译得只能让人呵呵了. 你要是忙,别接那么多活好不啦. 现在都在说供给侧改革,都在大力提倡工匠精神,我们做技术的,还是踏实点好 ...
- Spark Streaming源码解读之No Receivers彻底思考
本期内容 : Direct Acess Kafka Spark Streaming接收数据现在支持的两种方式: 01. Receiver的方式来接收数据,及输入数据的控制 02. No Receive ...
- 读艾伦的jQuery的无new构建,疑惑分析——jquery源码学习一
背景: 有心学习jquery源码,苦于自己水平有限,若自己研究,耗时耗力,且读懂之日无期. 所以,网上寻找高手的源码分析.再经过自己思考,整理,验证.以求有所收获. 此篇为读高手艾伦<jQuer ...
- 使用es6的set和map实现数组去重复
var set = new Set();var arr = [1, 2, 3, 3, 2, 1];arr.map(val => set.add(val));// arr.map(function ...
- win10环境下ue4使用游戏手柄输入
忙里偷闲,趁着源码编译需要好久的时间,把这篇博客补上,来说说怎么在win10环境中,ue4使用游戏手柄输入,也就是gamepad输入. 1.我用的手柄是rapoo v10 这款手柄,连接无线USB之后 ...
- WLAN频段的选择
WLAN(无线局域网)通过射频技术,将设备之间互联.当前应用于WLAN组网的有WIFI,蓝牙等.蓝牙工作在2.4GHZ的ISM(工业.科研.医疗)频段,功率等级分为0dBm,10dBm,20dBm:发 ...
- linux 关于用户与组的操作
1.添加用户: useradd handongyu 2.查看所有用户 cat /etc/passwd 查看某一用户用 cat /etc/passwd |grep root 3.查看所有组 ca ...
- Hex string convert to Binary String and Vise-Versa(16进制和2进制字符串的相互转换)
这个转换在我们日常的编码中还是很有机会遇到的,这里贴出来和大家分享探讨. void pu_hex_to_binary(std::string strHex, std::string &strB ...
- CSS3基础03(3D②) 求粉丝
3 D (3.1)rotateY 围绕着Y轴进行旋转 (1)正数是(站在右边推),负数是(站在左边推) (2.1)定义元素背过去是否可见 backface-visibility: visible|hi ...
- HDOJ(1238) KMP
Substrings http://acm.hdu.edu.cn/showproblem.php?pid=1238 先找到长度最短的字符串,把它的子串和该子串的逆序(按长度从大到小)依次与其他字符串匹 ...