博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5464 Clarke and problem(DP 01背包)
阅读量:4139 次
发布时间:2019-05-25

本文共 1887 字,大约阅读时间需要 6 分钟。

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

BestCoder Round #56 (div.2) 

/*01背包DP*/#include 
#include
#include
#include
#include
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
#include
#include
#include
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

转载地址:http://zfmvi.baihongyu.com/

你可能感兴趣的文章
阿里p8程序员四年提交6000次代码的确有功,但一次错误让人唏嘘!
查看>>
一道技术问题引起的遐想,最后得出结论技术的本质是多么的朴实!
查看>>
985硕士:非科班自学编程感觉还不如培训班出来的,硕士白读了?
查看>>
你准备写代码到多少岁?程序员们是这么回答的!
查看>>
码农:和产品对一天需求,产品经理的需求是对完了,可我代码呢?
查看>>
程序员过年回家该怎么给亲戚朋友解释自己的职业?
查看>>
技术架构师的日常工作是什么?网友:搭框架,写公共方法?
查看>>
第四章 微信飞机大战
查看>>
九度:题目1008:最短路径问题
查看>>
九度Online Judge
查看>>
九度:题目1027:欧拉回路
查看>>
九度:题目1012:畅通工程
查看>>
九度:题目1017:还是畅通工程
查看>>
九度:题目1034:寻找大富翁
查看>>
第六章 背包问题——01背包
查看>>
第七章 背包问题——完全背包
查看>>
51nod 分类
查看>>
1136 . 欧拉函数
查看>>
面试题:强制类型转换
查看>>
Decorator模式
查看>>