HDU 5534 Partial Tree (2015长春站H题&&完全背包)
来源:互联网 发布:java判断全角字符 编辑:程序博客网 时间:2024/05/16 06:38
今天写了这题,再次感慨,失去了拿我们学校首金的机会,今天花了20分钟1A了这题。这么简单的背包DP,比赛的时候被我想那么复杂,我花了2个小时搞了这题,看到题目我就想想到了是背包DP,然后开心地列了一个二维背包DP方程,一直想着降维,优化,始终没有搞定,也考虑了一开始先给每个点分配一个度数,然后现有的度数变成了了
这道题不想多说什么,只给给一个转移方程:
这里
下面是代码:
#include <bits/stdc++.h>#define LL long long#define FOR(i,x,y) for(int i = x;i < y;++ i)#define IFOR(i,x,y) for(int i = x;i > y;-- i)using namespace std;const int maxn = 2020;const int inf = 0x3fffffff;int dp[maxn<<1],c[maxn],w[maxn];;int n,m;void init(){ scanf("%d",&n); FOR(i,1,n) scanf("%d",&w[i]),c[i] = i;}void work(){ if(n == 2) {printf("%d\n",2*w[1]);return;} m = n-2; FOR(i,0,n<<1) dp[i] = -inf; w[0] = w[1]; dp[0] = n*w[0]; n --; FOR(i,1,n) w[i] = w[i+1]-w[0]; FOR(i,1,n){ FOR(v,c[i],m+1){ dp[v] = max(dp[v],dp[v-c[i]]+w[i]); } } printf("%d\n",dp[m]);}int main(){ //freopen("test.in","r",stdin); int T; scanf("%d",&T); while(T--){ init(); work(); } return 0;}
0 0
- HDU 5534 Partial Tree (2015长春站H题&&完全背包)
- HDU-5534-Partial Tree【2015长春赛区】【完全背包】
- HDU-5534-Partial Tree【2015长春赛区】【完全背包】
- HDU 5534 【2015长春现场赛 H】 Partial Tree
- hdu 5534 Partial Tree(完全背包)
- HDU 5534 Partial Tree(完全背包)
- HDU 5534 Partial Tree(完全背包)
- HDU 5534 Partial Tree (完全背包)
- hdu 5534 Partial Tree(完全背包)
- hdu 5534 Partial Tree(完全背包)
- hdu 5534 Partial Tree(完全背包)
- hdu 5534 Partial Tree【完全背包】
- HDU 5534 Partial Tree 【完全背包+思维】
- 【HDU5534 2015长春赛区H】【树上DP转完全背包】Partial Tree 不同度不同权对应最大树权
- HDU 5534 Partial Tree (变形完全背包 好题)
- [hdu 5534]2015ACM/ICPC亚洲区长春站 Partial Tree 完全背包
- HDU 5534 Partial Tree ACM/ICPC 2015 Changchun(完全背包)
- [HDU 5534] Partial Tree (完全背包问题) (好题)
- Linux seq 命令
- HDU 5536 Chip Factory (暴力 或者 01Trie)
- python中format的实例
- 去除 JavaScript 代码的怪味
- 设计模式之--装饰者模式
- HDU 5534 Partial Tree (2015长春站H题&&完全背包)
- OC03 避免互相引入 方法理解5
- Maven多模块布局实例详解
- 关于手机端手势js库的选择:hammer.js
- 151102笔记
- IP地址 网段的划分
- cocos-js 的事件监听(学习)
- BFS Codeforces591E Three States
- OC04 NSString、NSArray、NSNumber