2015长春 HDU 5534 Partial Tree
题意:有n个结点,n-1条边,现在要把这n个结点连成一棵树,给定了f(i),表示度为i的结点的价值是f(i)。现在问如何连能够使得Σf(i)的值最大。
思路:每个点至少一个度,所以可分配的度数为n-2,那么剩下就是每种物品可以任意选,转化成背包问题。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#define clc(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=;
const int maxnode=;
const int inf=0x3f3f3f3f;
typedef long long LL; int main()
{
int t,n;
int f[],dp[];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=; i<n; i++)
{
scanf("%d",&f[i]);
}
clc(dp,);
dp[]=n*f[];
for(int i=;i<=n-;i++)
{
for(int j=i;j<=n-;j++)
{
dp[j]=max(dp[j],dp[j-i]+f[i+]-f[]);//容量为j的背包增加i度后的价值
}
}
printf("%d\n",dp[n-]);
}
return ;
}
2015长春 HDU 5534 Partial Tree的更多相关文章
- HDU 5534 Partial Tree 完全背包
一棵树一共有2*(n-1)度,现在的任务就是将这些度分配到n个节点,使这n个节点的权值和最大. 思路:因为这是一棵树,所以每个节点的度数都是大于1的,所以事先给每个节点分配一度,答案 ans=f[1] ...
- 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= ...
- 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(每种都装的完全背包)
Partial Tree In mathematics, and more specifically in graph theory, a tree is an undirected graph in ...
- HDU 5534 Partial Tree (完全背包变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题意: 给你度为1 ~ n - 1节点的权值,让你构造一棵树,使其权值和最大. 思路: 一棵树上 ...
- HDU 5534 Partial Tree
2015 ACM/ICPC 长春现场赛 H题 完全背包 #include<cstdio> #include<cstring> #include<cmath> #in ...
- ACM学习历程—HDU 5534 Partial Tree(动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题目大意是给了n个结点,让后让构成一个树,假设每个节点的度为r1, r2, ...rn,求f(x ...
- hdu 5534 Partial Tree(完全背包)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5534 题解:这题一看有点像树形dp但是树形dp显然没什么思路.然后由于这里的约束几乎没有就 ...
随机推荐
- 为什么hibernate需要事务?
Hibernate是对JDBC的轻量级对象封装, Hibernate本身是不具备事务处理功能的,Hibernate事务实际上是底层的JDBC事务的封装,或者是JTA事务的封装. Hibernate的J ...
- js页面刷新一次
// var str = document.location.hash, // index = str.indexOf("#"); // if(index == 0){ // wi ...
- js按钮点击展开收起
$('.tab').click(function(){ var index = $('.tab').index(this), //缓存第一次点击的li的索引值 ele = $(this).find(' ...
- DEDECMS采集规则,过滤,替换文章内的部分内容
1.采集去除链接[Copy to clipboard]CODE:{dede:trim}]*)>([^<]*){/dede:trim}---------------------------- ...
- hdu 1028
递推 #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> ...
- hdu 4665
转载一下 用的搜索 竟然过了 ............代码 ....... #include<stdio.h> #include<string.h> #include&l ...
- SDUT 2523 OOXX
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2523 思路 :就是先统计一下方阵中1多少2多少 ...
- 推荐牛X的一本JS书
主要是看阮一峰的教程时,他参考书目里有这一本中文的, 找来一看,果然高.. 练习一下. function Base(name) { this.name = name; this.getName = f ...
- linux Ubuntu安装后没有引导 解决方案
用EasyBCD添加ubuntu grub2引导,适用于12.04 及之前版本的ubuntu安装好easybcd后运行,之后看图
- 观察者模式实现INotifyPropertyChanged
其实一直不知道INotifyPropertyChanged这个接口中PropertyChanged事件是什么时候有值的,因为在使用的时候,只要按步骤来就可以,因为我自己并没有对这个事件赋值,所以很好奇 ...