hdu 5534(dp)
2015-11-04 13:52
274 查看
[align=left]Input[/align]
The first line contains an integer T indicating 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.
Output
For each test case, please output the maximum coolness of the completed tree in one line.
Sample Input
2
3
2 1
4
5 1 4
Sample Output
5
19
题意:老实说,开始看了半天并没有看懂题- -。
给你n个点,然后要求添加n-1条边,每个节点都有度(入度+出度),度的数量对应不同的权值,求树的最大权值
思路:总共有2*(n-1)个度,首先,每个点都先有一个度,然后分配剩下的n-2个度给n个点使它们最大,
于是就成了背包问题 /* 感觉动规怎么都不会,是时候去学学了
/*表示从题没看懂那一刻,就注定做不出来,于是只有去看别人的报告了- -
The first line contains an integer T indicating 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.
Output
For each test case, please output the maximum coolness of the completed tree in one line.
Sample Input
2
3
2 1
4
5 1 4
Sample Output
5
19
题意:老实说,开始看了半天并没有看懂题- -。
给你n个点,然后要求添加n-1条边,每个节点都有度(入度+出度),度的数量对应不同的权值,求树的最大权值
思路:总共有2*(n-1)个度,首先,每个点都先有一个度,然后分配剩下的n-2个度给n个点使它们最大,
于是就成了背包问题 /* 感觉动规怎么都不会,是时候去学学了
/*表示从题没看懂那一刻,就注定做不出来,于是只有去看别人的报告了- -
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <queue> #include <vector> #include <algorithm> #include <functional> //看懂题好不容易- - using namespace std; int a[20005]; int dp[20005]; int main() { int cas,n; scanf("%d",&cas); while(cas -- ) { scanf("%d",&n); for(int i = 0; i < n-1; i++) scanf("%d",a+i); int all = n-2; int ans = a[0]*n; for(int i = 1; i <= n; i++) dp[i] = -0x3f3f3f3f; dp[0]= ans; for(int i = 1; i < n-1; i++) a[i] -= a[0]; for(int i = 1; i <= all; i++) { for(int j = i; j <= all; j++) { dp[j] = max(dp[j],dp[j-i] + a[i]); } } printf("%d\n",dp[all]); } return 0; }
相关文章推荐
- unity3d 抛物线
- MATLAB中如何输入希腊字母
- hdu 5534(dp)
- 黑马程序员——java基础语法(二)---流程控制、函数
- autocomplete
- AD备忘
- Deep Learning 6_深度学习UFLDL教程:Softmax Regression_Exercise(斯坦福大学深度学习教程)
- ELK系列--实时日志分析系统ELK 部署与运行中的问题汇总
- Android 3D滑动菜单完全解析,实现推拉门式的立体特效
- 初学者编了个象棋程序,工程完成度百分之九十五,跟大家分享下,希望下一步能做个图形界面,欢迎交流
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
- Android Stuido超全快捷键
- [THINKPHP] 模板可用三元操作符
- BootStrap学习(2)_下拉菜单&按钮组
- Android~AsyncTask异步操作DEMO学习解析
- SetDll DLL自动注入工具,让EXE在启动的时候加载自己做的DLL
- 减治法之插入排序(C实现)
- OC中有关JS的相关操作
- 关于做好ASO工作的十点有效建议
- hadoop入门例子(一)-输出hdfs上面的某一个目录下面的文件