hdu5534 Partial Tree
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 126 Accepted Submission(s): 68
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?
the total number of test cases.
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<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 99999999
int v[2200],dp[2200];
int main()
{
int n,m,i,j,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=1;i<=n-1;i++){
scanf("%d",&v[i]);
}
int ans=0;
ans+=v[1]*n;
for(i=2;i<=n-1;i++){
v[i]-=v[1];
}
for(i=1;i<=n-2;i++){
dp[i]=-inf;
}
dp[0]=0;
for(i=1;i<=n-2;i++){
v[i]=v[i+1];
}
for(i=1;i<=n-2;i++){
for(j=i;j<=n-2;j++){
dp[j]=max(dp[j],dp[j-i]+v[i]);
}
}
ans+=dp[n-2];
printf("%d\n",ans);
}
}
hdu5534 Partial Tree的更多相关文章
- HDU-5534 Partial Tree 完全背包 设定初始选择
题目链接:https://cn.vjudge.net/problem/HDU-5534 题意 放学路上看到n个节点,突然想把这几个节点连成一颗树. 树上每个节点有一个清凉度,清凉度是一个关于节点度的函 ...
- 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 背包DP
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- 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)对应的不同的权值,然后问你在这些点形成树的前提下的所能形 ...
- Partial Tree(DP)
Partial Tree http://acm.hdu.edu.cn/showproblem.php?pid=5534 Time Limit: / MS (Java/Others) Memory Li ...
- HDU - 5534 Partial Tree(每种都装的完全背包)
Partial Tree In mathematics, and more specifically in graph theory, a tree is an undirected graph in ...
随机推荐
- Flutter 基础组件:单选框和复选框
前言 Material组件库中提供了Material风格的单选开关Switch和复选框Checkbox,虽然它们都是继承自StatefulWidget,但它们本身不会保存当前选中状态,选中状态都是由父 ...
- Vue基础语法与指令
项目初始化 用vscode打开终端,输入npm init -y生成package.json 然后安装vue npm install vue 需要注意的是,我遇到了这个问题 出现原因:文件夹名和生成的p ...
- 安装sendmail
yum install -y sendmail yum install -y sendmail-cf 启动 service sendmail start 发送邮件 cat nihao.txt |mai ...
- CTFHub - Web(六)
命令注入: 1.进入页面,测试127.0.0.1, 关键代码: <?php $res = FALSE; if (isset($_GET['ip']) && $_GET['ip'] ...
- ctfhub技能树—信息泄露—git泄露—Stash
打开靶机环境 查看页面内容 使用dirsearch进行扫描 使用Githack工具处理git泄露情况 进入.git/refs目录 发现stash文件,使用notepad++打开文件 使用git dif ...
- 三节锂电池充电管理芯片,IC电路图如何设计
关于三节锂电池供电的产品,在三节锂电池上,需要三个电路系统: 1,三节锂电池保护电路, 2,三节锂电池充电电路, 3,三节锂电池输出电路. 1.三节锂电池保护电路,芯片电路图 控制三节锂电池池的充电电 ...
- 【源码解读】js原生消息提示插件
效果如下: 关闭message后前后message的衔接非常丝滑,这部分是我比较感兴趣的.带着这个问题先了解下DOM结构,顺便整理下作者的思路. 从DOM里我们可以看到所有的message都在一个容器 ...
- 注入器(injector)
1.0 注入器/injector 注入器是AngularJS框架实现和应用开发的关键,这是一个DI/IoC容器的实现. AngularJS将功能分成了不同类型的组件分别实现,这些组件有一个统称 ...
- .NET Core 问题记录
前言: 最近在项目中遇到了遇到了写部署步骤过多的问题,为了减少.net core项目部署步骤:需要对一些基础问题进行验证: 如端口设置.单页应用程序(angluar)合并部署方式等相关问题,特将解决过 ...
- 阿里云OSS对象存储服务(二)
一.使用SDK 在OSS的概览页右下角找到"Bucket管理",点击"OSS学习路径" 点击"Java SDK"进入SDK开发文档 二.创建 ...