2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree
Partial Tree
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 228 Accepted Submission(s): 138
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 <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define MLL (1000000000000000001LL)
#define INF (1000000001)
#define For(i, s, t) for(int i = (s); i <= (t); i ++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i --)
#define Rep(i, n) for(int i = (0); i < (n); i ++)
#define Repn(i, n) for(int i = (n)-1; i >= (0); i --)
#define mk make_pair
#define ft first
#define sd second
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define sz(x) ((int) (x).size())
#define clr(x, y) (memset(x, y, sizeof(x)))
inline void SetIO(string Name)
{
string Input = Name + ".in";
string Output = Name + ".out";
freopen(Input.c_str(), "r", stdin);
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
char ch = ' ';
int Ret = ;
bool Flag = ;
while(!(ch >= '' && ch <= ''))
{
if(ch == '-') Flag ^= ;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
Ret = Ret * + ch - '';
ch = getchar();
}
return Ret;
} const int N = ;
int n, F[N];
int Dp[N]; inline void Solve(); inline void Input()
{
int TestNumber = Getint();
while(TestNumber--)
{
n = Getint();
For(i, , n - ) F[i] = Getint();
Solve();
}
} inline void Solve()
{
For(i, , n - ) F[i] -= F[];
Dp[] = ;
For(i, , n - )
{
Dp[i] = F[i + ];
For(j, , (i / ) + )
Dp[i] = max(Dp[i], Dp[j] + Dp[i - j]);
}
printf("%d\n", Dp[n - ] + n * F[]);
} int main()
{
Input();
//Solve();
return ;
}
2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree的更多相关文章
- 2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building
House Building Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 2015ACM/ICPC亚洲区长春站 F hdu 5533 Almost Sorted Array
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- 2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b
Count a * b Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Tot ...
- 2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich
Too Rich Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- HDU 5534 Partial Tree 完全背包
一棵树一共有2*(n-1)度,现在的任务就是将这些度分配到n个节点,使这n个节点的权值和最大. 思路:因为这是一棵树,所以每个节点的度数都是大于1的,所以事先给每个节点分配一度,答案 ans=f[1] ...
- hdu 5534 Partial Tree 背包DP
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
随机推荐
- Android学习笔记之打钩显示输入的密码
利用EditText作为密码输入框是个不错的选择(只需设置输入类型为textPassword即可),保密且无需担心被盗取.但有时用户也不知道自己输入的是否正确,这时就应该提供一个“显示密码”的复选框, ...
- Android--UI之EditText
前言 上一篇博客介绍了Android的TextView控件,这篇博客来说一下EditText控件.EditText为一个文本控件,提供了文本输入的功能,而且继承自TextView,可以理解为可以输入的 ...
- 高流量站点NGINX与PHP-fpm配置优化
导读 使用Nginx搭配PHP已有7年的经历,这份经历让我们学会如何为高流量站点优化NGINX和PHP-fpm配置. 以下正是这方面的一些提示和建议: 1. 将TCP切换为UNIX域套接字 1. 将T ...
- Inheritance
Often, classes will have shared characteristics with other classes. Rewriting the same methods for e ...
- [BZOJ1786][BZOJ1831]逆序对
[BZOJ1786][BZOJ1831]逆序对 试题描述 输入 输出 输入示例 - - 输出示例 数据规模及约定 见“输入” 题解 首先这题有一个性质,即,填的数从左到右一定不降.证明不妨读者自己yy ...
- linux下创建库函数
来源: 在Linux下如何使用自己的库函数-riverok-ChinaUnix博客 http://blog.chinaunix.net/uid-21393885-id-88128.html 构建Lin ...
- 使用Webdriver执行JS小结
首先,我们使用如下方式初始化driver: WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptEx ...
- Meta Programming
[本文链接] http://www.cnblogs.com/hellogiser/p/meta-programming.html [分析] Template Mataprogram,中文叫模板元编程. ...
- 【转】Linux Shell脚本调试技术
本文转载自:https://www.ibm.com/developerworks/cn/linux/l-cn-shell-debug/ Shell脚本调试技术 本文全面系统地介绍了shell脚本调试技 ...
- CStringUtf8ToUnicode
CString CStringUtf8ToUnicode( CString Utf8 ) { int wLen = 0; CString strUnicode; LPSTR pBufChar = NU ...