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
Now, as DRD’s friend, ATM wants to know how many clones can survive at most.
Input
The first line contains an integer
For each test case: The first line contains 1 integer
Output
For each test case, output an integer representing the answer MOD
Sample Input
2
1
5
2
8 6
Sample Output
1
7
题意
克隆人有
如果
分析
我们可以发现,如果所有人的属性值和相同那么它们都可以存活,因为每两个人中要么所有属性相同,要么至少有两个属性一高一低,所以它们可以存活。
而且当它们的属性和恰好为
定义
显边界条件
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;
}