HDU-5464-Clarke and problem
2016-07-25 22:16
120 查看
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.
题解:用dp[i][j]存储前i个数的任意组合对p取模为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
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.
题解:用dp[i][j]存储前i个数的任意组合对p取模为j的方法数
#include<iostream> using namespace std; #define Mod 1000000007 int dp[1005][1005]; int main() { int a[1005]; int T, n, p; cin >> T; while (T--) { cin >> n >> p; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] = (a[i] % p + p) % p; } memset(dp, 0, sizeof(dp)); dp[0][0] = 1; int x; for (int i = 1; i <= n; i++) { for (int j = 0; j < p; j++) { x = (j + a[i]) % p; dp[i][x] = (dp[i - 1][j] + dp[i - 1][x]) % Mod; } } cout << dp [0] << endl; } return 0; }
相关文章推荐
- 详解Android应用中屏幕尺寸的获取及dp和px值的转换
- 基于Android中dp和px之间进行转换的实现代码
- Android中dip、dp、sp、pt和px的区别详解
- 简单的四则运算
- 数的奇偶性
- ACMer博客瀑布流分析
- LFC1.0.0 版本发布
- ACM程序设计大赛题目分类
- 2015年acm国内排名
- Android dpi,dip,dp的概念以及屏幕适配
- 计算字符串最后一个单词长度
- Android px、dp、sp之间相互转换
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- HP data protector软件学习1--基本角色与基本工作流程
- HP data protector软件学习2--软件组成与界面介绍
- 矩阵的乘法操作
- android中像素单位dp、px、pt、sp的比较