Problem Description
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a student and read a book.
Suddenly, a difficult problem appears: 
You are given a sequence of number a1,a2,...,an and a number p. Count the number of the way to choose some of number(choose none of them is also a solution) from the sequence that sum of the numbers is a multiple of p(0 is also count as a multiple of p). Since the answer is very large, you only need to output the answer modulo 109+7
 

 

Input
The first line contains one integer T(1T10) - the number of test cases. 
T test cases follow. 
The first line contains two positive integers n,p(1n,p1000) 
The second line contains n integers a1,a2,...an(|ai|109).
 

 

Output
For each testcase print a integer, the answer.
 

 

Sample Input
1
2  3
1  2
 

 

Sample Output
2

  设dp[i][j]表示到第i个元素余数为j的个数。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 #define modelo 1000000007
 6 int a[1005];
 7 int dp[1005][1005];
 8 int main()
 9 {
10     int n,t,q,i,j;
11     scanf("%d",&t);
12     while (t--)
13     {
14        scanf("%d%d",&n,&q);
15        for (i=1;i<=n;i++)
16        {
17           scanf("%d",&a[i]);
18           a[i]=(a[i]%q+q)%q;
19        }
20        memset(dp,0,sizeof(dp));
21        dp[0][0]=1;
22        for (i=1;i<=n;i++)
23        {
24           for (j=0;j<q;j++)
25           dp[i][j]=(dp[i-1][j]+dp[i-1][(j+a[i])%q])%modelo;
26        }
27        printf("%d\n",dp[n][0]);
28     }
29     return 0;
30 }

 

posted on 2015-09-21 13:40  pb2016  阅读(171)  评论(0编辑  收藏  举报