hdu5000一道很有意思的DP

题目描述

After eating food from Chernobyl, DRD got a super power: he could clone himself right now! He used this power for several times. He found out that this power was not as perfect as he wanted. For example, some of the cloned objects were tall, while some were short; some of them were fat, and some were thin.

More evidence showed that for two clones A and B, if A was no worse than B in all fields, then B could not survive. More specifically, DRD used a vector v to represent each of his clones. The vector v has n dimensions, representing a clone having N abilities. For the i-th dimension, v[i] is an integer between 0 and T[i], where 0 is the worst and T[i] is the best. For two clones A and B, whose corresponding vectors were p and q, if for 1 <= i <= N, p[i] >= q[i], then B could not survive.

Now, as DRD’s friend, ATM wants to know how many clones can survive at most.

算法思路

这题做了很长的一段时间,算是我的失误吧,但是找到的这个规律真的非常的有意思。
我前期一直在研究什么样的人可以共存,结果花了很长时间,但是当我研究不能共存的人的关系的时候,情况就变得不同了。
1. 如果两人的数据完全一样,那么他们不可共存,是为自反性。
2. 如果a人可以杀死b人,那么b人杀不死a人,是为反对称性。
3. 如果a可以杀死b,b可以杀死c,显然a也可以杀死c,是为传递性。
那么,就存在一个偏序关系,我们要找其中最长的一条反链。
我们可以发现,可以以数值总和划分这个偏序关系,这样找到的数量是最长的。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define MOD 1000000007
#define LL long long 
#define MAXN 2050

LL dp[2][MAXN];
int f[MAXN],n,t;

void Solve()
{
    memset(dp,0,sizeof(dp));
    int i,sum=f[0],j,k;
    for(i=0;i<=f[0];i++)
        dp[0][i] = 1;
    for(i=1;i<n;i++){
        sum += f[i];
        for(j=0;j<=sum;j++){
            dp[i&1][j] = 0;
            for(k=0;k<=f[i]&&j-k>=0;k++){
                dp[i&1][j] = (dp[i&1][j]+dp[(i-1)&1][j-k])%MOD;
            }
        }
    }
    printf("%lld\n",dp[(n-1)&1][sum/2]);
    return;
}

int main()
{
    freopen("input","r",stdin);
    int i;
    scanf("%d",&t);

    while(t--){
        scanf("%d",&n);
        for(i=0;i<n;i++)
            scanf("%d",&f[i]);

        Solve();
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值