Clone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 794 Accepted Submission(s): 392
Problem Description
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 10^9 + 7.
Sample Input
Sample Output
题意:克隆人有n种属性,如果A的每一种属性值都大于等于B,那么B将被杀死,问最多可以同时存活多少克隆人
思路:dp[i][j]表示前 i 种属性sum为 j 时的人数
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#define N 2009
int a[N];
using namespace std;
int sum;
int dp[N][N];
#define mod 1000000007
int main()
{
int n;
int t;
while(~scanf("%d",&t))
{
while(t--)
{
scanf("%d",&n);
memset(dp,0,sizeof dp);
int sum=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
for(int i=0;i<=a[1];i++)//如果只有一种属性,那么只有一个人存活
dp[1][i]=1;
sum/=2;
for(int i=2;i<=n;i++)
{
for(int j=0;j<=sum;j++)
{
for(int k=0;k<=a[i];k++)
{
if(j>=k)
{
dp[i][j]=(dp[i][j]+dp[i-1][j-k])%mod;
}
else break;
}
}
}
//for(int i=1;i<=n;i++)
//{
// for(int j=0;j<=sum;j++)
//cout<<dp[i][j]<<" ";
//cout<<endl;
//}
printf("%d\n",dp[n][sum]);
}
}
return 0;
}