HDU5000 Clone(计数dp)

Clone

传送门1
传送门2
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.

Input

The first line contains an integer T , denoting the number of the test cases.

For each test case: The first line contains 1 integer N , 1<=N<=2000 . The second line contains N integers indicating T[1],T[2],...,T[N] . It guarantees that the sum of T[i] in each test case is no more than 2000 and 1<=T[i] .

Output

For each test case, output an integer representing the answer MOD 109+7 .

Sample Input

2
1
5
2
8 6

Sample Output

1
7


题意

克隆人有 n 个属性,给出每个属性的最大值 T[i] ;属性值可以是 0T[i] ;
如果 A 的所有属性都不比 B 低,那么 B 就会挂,问最多存活多少人。

分析

我们可以发现,如果所有人的属性值和相同那么它们都可以存活,因为每两个人中要么所有属性相同,要么至少有两个属性一高一低,所以它们可以存活。
而且当它们的属性和恰好为 12ni=1T[i] ,也就相当于每个属性都取到平均值时会有更多人存活。
定义 dp[i][j] 表示前 i 种属性的和为 j 的情况有多少种,则

dp[i][j]=k=0min(T[i],j)dp[i1][jk].

显边界条件 dp[1][i]=1 .

CODE

#include<cstdio>
#include<memory.h>
#define N 2005
#define P 1000000007
int n,T,sum;
int A[N];
int dp[N][N];
int main() {
    scanf("%d",&T);
    while(T--) {
        sum=0;
        scanf("%d",&n);
        for(int i=1; i<=n; i++) {
            scanf("%d",A+i);
            sum+=A[i];
        }
        sum>>=1;
        memset(dp,0,sizeof dp);
        for(int j=0;j<=A[1];j++)dp[1][j]=1;
        for(int i=2;i<=n;i++)
            for(int j=0;j<=sum;j++)
                for(int k=0;k<=A[i]&&k<=j;k++)
                    dp[i][j]=(dp[i][j]+dp[i-1][j-k])%P;
        printf("%d\n",dp[n][sum]);
    }
    return 0;
}
发布了34 篇原创文章 · 获赞 44 · 访问量 5067

猜你喜欢

转载自blog.csdn.net/zzyyyl/article/details/78471939
今日推荐