HDU 5534 完全背包

Posted 树的种子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 5534 完全背包相关的知识,希望对你有一定的参考价值。

题目把Partial 都搬出来了,其实是有这样的定理,说一个长度为n-2的序列,(1~n)一定可以对应一棵树。

 

叉姐的思路:

其实也可以看成完全背包。

n-2个度的分派,每种度是一个物品,而且可以选很多次——完全背包了

然后要减去f(1),首先是默认的度都为1.

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2020;
int f[MAXN];
int d[MAXN];



int main()
{
    //freopen("in.txt","r",stdin);
    int T_T;
    scanf("%d",&T_T);
    while(T_T--) {
        int n;
        scanf("%d",&n);

        for(int i = 1; i <= n-1; i++) scanf("%d",&f[i]);

        memset(d,-1e9-7,sizeof(d));

        d[0] = n*f[1];

        for(int i = 1; i <= n-2; i++) {
            for(int j = 0; j <= n-2; j++) {
                if(j>=i)
                    d[j] = max(d[j],d[j-i]+f[i+1]-f[1]);
            }
        }

        cout<<d[n-2]<<endl;

    }

    return 0;
}

 

以上是关于HDU 5534 完全背包的主要内容,如果未能解决你的问题,请参考以下文章

hdu 5534 Partial Tree(完全背包)

HDU 5534 Partial Tree (完全背包变形)

HDU - 5534 Partial Tree(每种都装的完全背包)

Partial Tree---hdu5534(完全背包)

[HDOJ5534] Partial Tree(脑洞,完全背包)

解题报告:hdu1248寒冰王座 - 完全背包