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;
}