hdu 5534(dp)
来源:互联网 发布:网络mc第一红人大赛 编辑:程序博客网 时间:2024/06/07 16:09
Input
The first line contains an integer T indicating the total number of test cases.
Each test case starts with an integern in one line,
then one line withn−1 integers f(1),f(2),…,f(n−1) .
1≤T≤2015
2≤n≤2015
0≤f(i)≤10000
There are at most10 test cases with n>100 .
Each test case starts with an integer
then one line with
There are at most
Output
For each test case, please output the maximum coolness of the completed tree in one line.
Sample Input
232 145 1 4
Sample Output
519
题意:老实说,开始看了半天并没有看懂题- -。
给你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;}
0 0
- hdu 5534(dp)
- HDU 5534 Partial Tree(dp)
- HDU 5534 Partial Tree(dp优化)
- hdu 5534 dp
- HDU 1024(DP)
- HDU 1087(DP)
- HDU 1506(DP)
- hdu 1058 (DP)
- hdu 1208 (DP)
- hdu 4502(DP)
- hdu 4561(DP)
- hdu 1292 (dp)
- hdu 2182 (dp)
- hdu 2955(DP)
- hdu 2546(dp)
- hdu 3466 (dp)
- hdu 3186(dp)
- hdu 1203(dp)
- Unity3d使用高通Vuforia发布IOS工程遇见缺少插件问题解决
- ReactiveCocoa2 源码浅析
- Android保存图片到系统图库 或者指定文件夹
- 计算机网络 - 运输层
- 【四】ODB - C++ 单表更新(V1.11)
- hdu 5534(dp)
- lightoj 1116 - Ekka Dokka 【分解因子】
- android 休眠唤醒机制分析(一) — wake_lock
- Maven的安装与使用
- 凸优化(一)——Introduction
- Hibernate之主键生成策略
- android-studio安装过程详解
- lazy懒加载(延迟加载)UITableView
- Android 3D滑动菜单完全解析,实现推拉门式的立体特效