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; } }
相关文章推荐
- Leetcode74: Best Time to Buy and Sell Stock III
- js 限制只能输入数字和一个小数,且第一位不能为小数
- <转>主流蓝牙BLE控制芯片详解(4):Nordic nRF51822
- linux常用命令(46):telnet 命令
- struts配置中,页面跳转
- proxy-target-class="true" 与proxy-target-class="false"的区别
- JAVA导出Excel(支持多sheet)
- 使用phpstorm来进行svn提交
- elasticsearch csv plugin
- Ueditor结合七牛云及百度云存储(JAVA版,ueditor-1.4.3)实现图片文件上传
- Spring Data Jpa 详解
- MongoDB运行状态、性能监控,分析
- 修练8年C++面向对象程序设计之体会
- svn下本地工程在服务器上的url以及信息
- 怎么快速 把一个 监听事件 变成 一个 内部类 在编程一个新的 java文件
- 数据库把一项设置成为不能重复的
- RHEL7 CENTOS7
- VS2010中汉字拷贝到Word出现乱码问题解决
- Java 二分查找的简单使用
- 利用PHP fsockopen 模拟POST/GET传送数据的方法