HDU 5464 Clarke and problem(DP 01背包)
来源:互联网 发布:es6对象转化为数组 编辑:程序博客网 时间:2024/04/29 01:46
Clarke and problem
Time Limit 20001000 MS (JavaOthers) Memory Limit 6553665536 K (JavaOthers)
Total Submission(s) 400 Accepted Submission(s) 179
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.
Source
Time Limit 20001000 MS (JavaOthers) Memory Limit 6553665536 K (JavaOthers)
Total Submission(s) 400 Accepted Submission(s) 179
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.
Source
BestCoder Round #56 (div.2)
/*01背包DP*/#include <iostream>#include <cstdio>#include <algorithm>#include <cstdlib>#include <string.h>using namespace std;const int N=1000+10;const int mod=1e9+7;int num[N];int p,n;int dp[N][N];int main(){int t,i,j;scanf("%d",&t);while(t--){memset(dp,0,sizeof(dp));dp[0][0]=1;scanf("%d%d",&n,&p);for(i=1;i<=n;i++){scanf("%d",&num[i]);num[i]%=p;//这里被刘大哥指明... 处理负数的 将他变成整数 num[i]=(num[i]+p)%p; } for(i=1;i<=n;i++){ //枚举每个数拿还是不拿 for(j=0;j<p;j++){ //枚举余数 //不拿 就是余数为j加上i-1余数为j的数量 dp[i][j]=(dp[i][j]+dp[i-1][j])%mod; //拿就 是余数为拿后的加上前I-1余数为拿前的 dp[i][(j+num[i])%p]=(dp[i][(j+num[i])%p]+dp[i-1][j])%mod;}}printf("%d\n",dp[n][0]);} return 0;}/* 暴搜超时 *//*#include <iostream>#include <cstdio>#include <algorithm>#include <cstdlib>using namespace std;const int N=1000+10;const int mod=1000000000+7;int num[N];int p,n;int re;void dfs(int now,int sum){int i;if(sum%p==0) { re++; re%=mod; return; }else if(sum>p||now>=n) return;dfs(now+1,sum+num[now]);dfs(now+1,sum);}int main(){int t,i;scanf("%d",&t);while(t--){re=1;scanf("%d%d",&n,&p);for(i=0;i<n;i++) scanf("%d",&num[i]);sort(num,num+n);dfs(0,0);printf("%d\n",re);} return 0;}*/
0 0
- HDU 5464 Clarke and problem(DP 01背包)
- HDU 5464 Clarke and problem(01背包)
- HDU 5464 Clarke and problem(类01背包)
- HDU 5464Clarke and problem(DP)
- hdu 5464 Clarke and problem(DP)
- hdu 5464 Clarke and problem dp
- hdu 5464 Clarke and problem(dp)
- HDU 5464:Clarke and problem
- HDU 5464 Clarke and problem
- HDU 5464Clarke and problem
- HDU-5464-Clarke and problem
- HDU 5469 Clarke and problem (DP)
- hdoj 5464 Clarke and problem 【DP】
- hdu 5464 Clarke and problem 动态规划
- hdu5464 Clarke and problem(DP)
- hdu5464 Clarke and problem (dp)
- hdu 5464 Clarke and problem (BestCoder Round #56 (div.2))
- HDOJ-5446 Clarke and problem(DP)
- Java多线程基础知识(三)
- Ros Navigation基础
- mantis的安装
- Android--shape-指定图形的corners、gradient、padding、size、solid、stroke属性
- Objective-C中get/set方法初探(1)
- HDU 5464 Clarke and problem(DP 01背包)
- 进程间通信IPC
- [svn常用命令使用总结]
- Java 加密算法
- java开发前奏
- SpringMVC 自定义拦截器使用
- python的【列表list】:定义、索引、添加、删除、遍历、长度;组合、重复、反转、切片、比较;排序
- android Flag启动模式
- 思想上移,行动下移,反思今目标使用不规范