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.

~开心,自己根据写出来的,还特别简洁。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <algorithm>
  7. #include <vector>
  8. #define ll __int64
  9. #define mod 1000000007
  10. using namespace std;
  11. int dp[][],nums[];
  12. int main(void)
  13. {
  14. int t;
  15. cin>>t;
  16. while(t--)
  17. {
  18. int n,p;
  19. scanf("%d %d",&n,&p);
  20. for(int i = ; i <= n; i++)
  21. {
  22. scanf("%d",&nums[i]);
  23. nums[i] %= p;
  24. if(nums[i] < )
  25. nums[i] += p;
  26. }
  27.  
  28. memset(dp,,sizeof(dp));
  29. dp[][] = ;
  30. for(int i = ; i <= n; i++)
  31. {
  32. for(int j = ; j <= p; j++)
  33. {
  34. dp[i][j] = dp[i-][j] + dp[i-][(j-nums[i]+p)%p];
  35. dp[i][j] %= mod;
  36. }
  37. }
  38. printf("%d\n",dp[n][]);
  39. }
  40. return ;
  41. }

dp hdu 5464 Clarke and problem的更多相关文章

  1. HDU 5464 Clarke and problem 动态规划

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5464 Clarke and problem  Accepts: 130  Submissions: ...

  2. hdu 5464 Clarke and problem dp

    Clarke and problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...

  3. HDU 5464 ( Clarke and problem ) (dp)

    dp[i][j] := 前i个数和为j的情况(mod p) dp[i][j] 分两种情况 1.不选取第i个数 -> dp[i][j] = dp[i-1][j] 2.   选取第i个数 -> ...

  4. HDU 5464:Clarke and problem

    Clarke and problem  Accepts: 130  Submissions: 781  Time Limit: 2000/1000 MS (Java/Others)  Memory L ...

  5. BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)

    今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem 和Codeforces Round #319 (Div. 2) B Modulo Sum思路差不 ...

  6. HDU 5628 Clarke and math——卷积,dp,组合

    HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...

  7. [HDU 5293]Tree chain problem(树形dp+树链剖分)

    [HDU 5293]Tree chain problem(树形dp+树链剖分) 题面 在一棵树中,给出若干条链和链的权值,求选取不相交的链使得权值和最大. 分析 考虑树形dp,dp[x]表示以x为子树 ...

  8. hdu 2993 MAX Average Problem(斜率DP入门题)

    题目链接:hdu 2993 MAX Average Problem 题意: 给一个长度为 n 的序列,找出长度 >= k 的平均值最大的连续子序列. 题解: 这题是论文的原题,请参照2004集训 ...

  9. cdq分治(hdu 5618 Jam's problem again[陌上花开]、CQOI 2011 动态逆序对、hdu 4742 Pinball Game、hdu 4456 Crowd、[HEOI2016/TJOI2016]序列、[NOI2007]货币兑换 )

    hdu 5618 Jam's problem again #include <bits/stdc++.h> #define MAXN 100010 using namespace std; ...

随机推荐

  1. 类欧几里德算法(洛谷 P5170

    #include <iostream> #include <cstdio> #include <queue> #include <algorithm> ...

  2. C++ Builder VCL库函数简介

    C++ Builder VCL库函数简介 2002-07-05· · ··C++builder资源中心 1 2 3 下一页 一.BORLAND C++ BUILDER VCL的内存管理函数 1. Al ...

  3. css正則匹配、模糊匹配

    //所有class包含font-red的p标签 p[class~="font-red"] {color: red;} [abc^="def"] 选择 abc 属 ...

  4. 解决git每次输入密码,设置gitlab、github默认push的用户名和密码

    git ssh key配置&解决git每次输入密码   欢迎加入qq群(IT-程序猿-技术交流群):757345416 在使用git时,每次pull/push都需要输入密码,有时大大降低了我们 ...

  5. idea配置tomcat中war和war exploded的区别

    是选择war还是war exploded 这里首先看一下他们两个的区别: war模式:将WEB工程以包的形式上传到服务器 :war exploded模式:将WEB工程以当前文件夹的位置关系上传到服务器 ...

  6. 《DSP using MATLAB》Problem 8.9

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  7. 0617Python-介绍、三种运行方式、变量、标识符和关键字、获取属性

    一.什么是自动化测试? 1.定义 自动:让机器自己动,就是自动 自动化:让机器按照人类的要求,把软件的所有功能遍历一遍 2.传统测试和自动化测试的区别 传统测试:繁琐.机械.门槛低.工资低 自动化测试 ...

  8. Python GUI文本编辑器

    使用Python编写一个简单的文本编辑器,需要展示一个用户界面,功能包括打开.保存文本文件. 使用tkinter库来编写GUI. #简单GUI文本编辑器 from tkinter import * f ...

  9. <每日一题>题目13:列表的简单问题

    ''' 分析: python赋值是通过指针来进行的. 很显然第一.三.四次调用都指向同一个列表,并未完成清空, 第二次调用只是指向了另一个列表,也未完成清空,很显然结果是累计的 结果: [0, 1] ...

  10. ubuntu与xshell连接不起来: