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.

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

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#define ll __int64
#define mod 1000000007
using namespace std;
int dp[][],nums[];
int main(void)
{
int t;
cin>>t;
while(t--)
{
int n,p;
scanf("%d %d",&n,&p);
for(int i = ; i <= n; i++)
{
scanf("%d",&nums[i]);
nums[i] %= p;
if(nums[i] < )
nums[i] += p;
} memset(dp,,sizeof(dp));
dp[][] = ;
for(int i = ; i <= n; i++)
{
for(int j = ; j <= p; j++)
{
dp[i][j] = dp[i-][j] + dp[i-][(j-nums[i]+p)%p];
dp[i][j] %= mod;
}
}
printf("%d\n",dp[n][]);
}
return ;
}

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. Python-基本运算符与流程控制

    目录 基本运算符 算术运算符 比较运算符 赋值运算符 逻辑运算符 身份运算符 位运算符 成员运算符 运算符优先级 流程控制 if 判断 单分支结构 双分支结构 多分支结构 while 循环 while ...

  2. VS2010-MFC(对话框:创建对话框类和添加控件变量)

    转自:http://www.jizhuomi.com/software/153.html 前两讲中讲解了如何创建对话框资源.创建好对话框资源后要做的就是生成对话框类了.生成对话框类主要包括新建对话框类 ...

  3. Python学习day23-面向对象的编程

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  4. python 第三方库的安装方法

    一.看更大的python世界 python 全球计算生态的主站:python 社区 www.pypi.org 二.安装第三方库 1) pip 命令安装方法 1.1 安装第三方库 命令行输入pip in ...

  5. sql里面插入语句insert后面的values关键字可省略

    插入到表名(列值)后跟一个查询语句的话就代表值,简单的说就是后面select select出来的值就是要插入的值,即  insert into tb(字段名一,字段名二)select 字段名一,字段名 ...

  6. centos7.5安装公版mysql5.7.25

    ######### 卸载原来系统安装的包 # yum remove -y java cvs libselinux-devel postgresql mysql ecj jna sinjdoc 依赖包安 ...

  7. Web API 上传下载文件

    1.引用了一个第三方组件 ICSharpCode.SharpZipLib.Zip; 2.具体代码 实体类,可以用hashtable 替代 ,感觉hashtable 比较灵活 public class ...

  8. ArccGIS 10发布WFS服务并加载到Skyline中

    下面用ArcGIS Server 10.0将建筑物图层发布为WFS服务. (1)创建mxd文件.ArcMap打开建筑物图层,存为Buildings.mxd文件.注意:必须统一空间参考系,且要与图层的坐 ...

  9. Pycharm中运行Python代码的几种方式

    在pycharm中的Python代码运行会出现各种奇葩的问题,比如,密码输入时不显示或没有提示,给我们带来一些麻烦,下面介绍几种代码运行的几种方式: 一.直接运行(Run按钮或者快捷键shift+F1 ...

  10. 写一个网页进度loading

    作者:jack_lo www.jianshu.com/p/4c93f5bd9861 如有好文章投稿,请点击 → 这里了解详情 loading随处可见,比如一个app经常会有下拉刷新,上拉加载的功能,在 ...