您的位置:首页 > 其它

hdu5464(Clarke and problem)

2015-09-22 14:40 218 查看


Clarke and problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 532    Accepted Submission(s): 232


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(1≤T≤10) -
the number of test cases. 
T test
cases follow. 

The first line contains two positive integers n,p(1≤n,p≤1000) 

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

Hint:
2 choice: choose none and choose all.

<pre name="code" class="cpp">#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long d[1010][1010];
int main(){
int t;
scanf("%d",&t);
while(t --){
memset(d,0,sizeof(d));
d[0][0] = 1;
int n,p;
int a[1010];
scanf("%d%d",&n,&p);
for(int i = 1;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i = 1;i<=n;i++){
for(int j = 0;j<p;j++){
d[i][j] = (d[i][j]+d[i-1][j])%1000000007;
int z = (j+a[i])%p;
if(z < 0)z+=p;
d[i][z] = (d[i][z]+d[i-1][j])%1000000007;
}
}
cout<<d
[0]<<endl;
}
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: