Clone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 444 Accepted Submission(s): 214
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.
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].
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
2 1 5 2 8 6
Sample Output
1 7//看的人家的代码,是一道母函数题目的变形题目,唉,不会 //组合个数 第0个和第sum个一样,是对称的。所以中间的那个就是最大的 //有个规律,应该是解题的关键吧 如果属性和sum相同,肯定不会冲突,如果不同,最大的个数不受影响 //渣渣 加油!!! //Time:2014-915 #include<cstdio> #include<cstring> #include<algorithm> #define mod 1000000007 using namespace std; const int MAX=2004; __int64 dp[MAX][MAX];//不用64位会wa 表示第i只羊 sum为j时的数量 int a[MAX]; __int64 sum; __int64 get_ans(int N){ if(N==1) return 1;//如果只有一种属性只能存活一个 memset(dp,0,sizeof(dp)); for(int i=0;i<=a[1];i++)dp[1][i]=1;//第1只羊 sum 为i的个数 int M=sum>>1; for(int i=2;i<=N;i++){//二维数组的母函数 for(int j=0;j<=M;j++){ for(int k=0;k<=a[i]&&k+j<=M;k++){ dp[i][j+k]=(dp[i][j+k]+dp[i-1][j])%mod; } } } return dp[N][M]%mod; } void solve(){ int T,N; scanf("%d",&T); while(T--){ sum=0; scanf("%d",&N); for(int i=1;i<=N;i++){ scanf("%d",&a[i]); sum+=a[i]; } printf("%I64d\n",get_ans(N)); } } int main(){ solve(); return 0; }
//一位数组代码,wa,不知道为什么 #include<cstdio> #include<cstring> #include<algorithm> #define mod 1000000007 using namespace std; const int MAX=2004; __int64 c1[MAX],c2[MAX];//不用64位会wa int a[MAX]; __int64 sum; __int64 get_ans(int N){ if(N==1) return 1;//如果只有一种属性只能存活一个 memset(c1,0,sizeof(c1)); memset(c2,0,sizeof(c2)); for(int i=0;i<=a[1];i++)c1[i]=1;//第1只羊 sum 为1的个数 int M=sum>>1; for(int i=2;i<=N;i++){//一维数组的母函数 for(int j=0;j<=M;j++){ for(int k=0;k<=a[i]&&k+j<=M;k++){ c2[j+k]+=(c1[j+k]+c1[j])%mod; } } for(int j=0;j<=M;j++){ c1[j]=c2[j]; c2[j]=0; } } return c1[M]%mod; } void solve(){ int T,N; scanf("%d",&T); while(T--){ sum=0; scanf("%d",&N); for(int i=1;i<=N;i++){ scanf("%d",&a[i]); sum+=a[i]; } sort(a+1,a+N+1);//一维数组一定要记得排序 printf("%I64d\n",get_ans(N)); } } int main(){ solve(); return 0; }