hdu 5464 Clarke and problem(dp)
2015-09-21 13:40
423 查看
[align=left]Problem Description[/align]
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
[align=left]Input[/align]
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).
[align=left]Output[/align]
For each testcase print a integer, the answer.
[align=left]Sample Input[/align]
1
2 3
1 2
[align=left]Sample Output[/align]
2
设dp[i][j]表示到第i个元素余数为j的个数。
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
[align=left]Input[/align]
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).
[align=left]Output[/align]
For each testcase print a integer, the answer.
[align=left]Sample Input[/align]
1
2 3
1 2
[align=left]Sample Output[/align]
2
设dp[i][j]表示到第i个元素余数为j的个数。
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define modelo 1000000007 int a[1005]; int dp[1005][1005]; int main() { int n,t,q,i,j; scanf("%d",&t); while (t--) { scanf("%d%d",&n,&q); for (i=1;i<=n;i++) { scanf("%d",&a[i]); a[i]=(a[i]%q+q)%q; } memset(dp,0,sizeof(dp)); dp[0][0]=1; for (i=1;i<=n;i++) { for (j=0;j<q;j++) dp[i][j]=(dp[i-1][j]+dp[i-1][(j+a[i])%q])%modelo; } printf("%d\n",dp [0]); } return 0; }
相关文章推荐
- 在android中使用logback-android日志框架配置 slf4j + logback
- Docker体验 Ubuntu下安装
- 对安卓反编译点的一点收获
- 【笔记】HTML+CSS基础课程(慕课)-CSS部分
- UnityShader实例15:屏幕特效之Bloom
- redis实战之使用redis存储session数据
- DWR应用—快速入门篇
- 常用sql
- 为什么通信服务提供商需要实现SD-WAN
- 使用Struts2和jQuery EasyUI实现简单CRUD系统(三)——ajax,struts2使用json格式的交互
- 哈希函数的构造方法
- URAL 1119 Metro (DP动态规划)
- 磁盘I/O性能----RAID
- Xilinx 双口RAM Ipcore Teset(VHDL)
- docker使用基础总结
- 软件设计中的数据处理
- ApacheBench(ab)使用简介
- 413 Request Entity Too Large
- MSSQL - SQL Server2008附加数据库失败 错误号:5120
- getCurrentSession hibernate in web