HDU 5534 Partial Tree(dp 背包)
2017-10-13 19:14
381 查看
题目链接
Partial Tree分析
总共 2(n−2) 度, 度数为 i 价值是f[i], 先给每个点一度,那麽剩余 n-2 个点分配就好,这不就是背包吗但是很奇怪的是,我用滚动数组倒着dp的时候wa了????为什么???
AC code
#include<bits/stdc++.h> #define pb push_back #define mp make_pair #define PI acos(-1) #define fi first #define se second #define INF 0x3f3f3f3f #define INF64 0x3f3f3f3f3f3f3f3f #define random(a,b) ((a)+rand()%((b)-(a)+1)) #define ms(x,v) memset((x),(v),sizeof(x)) #define eps 1e-8 using namespace std; typedef unsigned long long ULL; typedef long long LL; typedef unsigned long long uLL; typedef long double DB; typedef pair<int,int> Pair; const int maxn = 1e5+10; const int MOD = 1e9+7; int dp[maxn]; int a[maxn]; int main() { // ios_base::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); int T; cin>>T; while (T--) { int n; cin>>n; for(int i=1 ; i<n ; ++i)cin>>a[i]; ms(dp,-INF); for(int i=2 ; i<n ; ++i)a[i]-=a[1]; dp[0] =a[1]*n; for(int i=1 ; i<=n-2 ; ++i){ for(int j = i ; j<=n-2 ; ++j){ dp[j] = max(dp[j],dp[j-i]+a[i+1]); } // for(int j=n-2 ; j>=i ; --j) // dp[j] = max(dp[j],dp[j-i]+a[i+1]); } std::cout << dp[n-2]<< '\n'; } return 0; }
相关文章推荐
- hdu 5534 Partial Tree 背包DP
- hdu 5534 Partial Tree 背包DP
- HDU 5534 Partial Tree (2015长春站H题&&完全背包)
- HDU 5534(Partial Tree-背包)
- HDU 5534 (ACM 2015 长春) Partial Tree [基础DP]
- [HDU 5534] Partial Tree (完全背包问题) (好题)
- HDU 5534 Partial Tree (完全背包变形)
- HDU-5534-Partial Tree【2015长春赛区】【完全背包】
- hdu 5534 Partial Tree(完全背包)
- HDU-5534 Partial Tree 完全背包 设定初始选择
- 【HDOJ5534】Partial Tree(树,背包DP)
- hdu 5534 Partial Tree(完全背包)
- HDU 5534 Partial Tree(完全背包)
- HDU 5534 Partial Tree ACM/ICPC 2015 Changchun(完全背包)
- HDU 5534 Partial Tree (完全背包)
- HDU 5534 Partial Tree (变形完全背包 好题)
- HDU 5534 Partial Tree 完全背包
- hdu 5534 Partial Tree(完全背包)
- HDU 5534 Partial Tree [完全背包]【动态规划+思维】
- hdu 5534 Partial Tree 2015长春区域赛 dp 脑洞