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 ;
}
最新文章
- 使用Apache的DigestUtils类实现哈希摘要(SHA/MD5)
- 找window的三种方法
- maven异常
- web压力测试工具
- (转)阴影锥(Shadow Volume)
- 【转】IOS屏幕旋转与View的transform属性之间的关系,比较底层
- 解决在 使用 AjaxFileUploder 插件时,不能获取返回的 json 结果数据
- (转)Maven实战(二)构建简单Maven项目
- Libgdx开发ios游戏
- 前端魔法堂——异常不仅仅是try/catch
- MYSQL数据库学习十八 数据库维护和性能提高
- G1 GC技术解析
- LOJ2831 JOISC2018 道路建设 LCT、树状数组
- 十二.HTTPS网站安全访问实践
- lua --- 表操作
- ztree删除某个节点下的全部子节点后,父节点图标还是文件夹
- 解决xadmin登录卡顿延迟的问题
- 音视频处理ffmpeg使用
- Easy Graphics Engine vs2015使用
- JBOSS安装与配置搭建本地项目环境(方便前端开发调式)