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. leetccode-130-被围绕的区域

    题目描述: 方法一:dfs class Solution: def solve(self, board: List[List[str]]) -> None: """ ...

  2. [JZOJ4648] 【NOIP2016提高A组模拟7.17】锦标赛

    题目 描述 题目大意 有nnn个人,你要确定一个出场序列.每次新上台的人就会和擂主打一架,胜利的人继续当擂主.题目给出两两之间打架胜利(失败)的概率. 问111选手坚持到最后的最大概率. 思考历程 看 ...

  3. js '' ""的嵌套使用

    1.我需要拼接一个字符串,但是其中 单引号内包含了双引号,双引号内又包含了单引号变量 这时我们想到了可以用到HTML特殊转义字符 2.如下拼接 return '<input type=" ...

  4. 前缀后缀——cf1167E

    想了很久没弄明白,对于边界的情况还是有问题 等题解出了再看看 然后枚举每个后缀r,找到比它小,并且在其左边的前缀l,那么删<=l,r-1的都可以 最后的二分很迷:要多考虑特殊情况:前缀跑到后缀后 ...

  5. 19-11-12-Aftern-℘

    我饿死了,于是写写博客安慰一下即将退役的自己. ZJ: T1. 三种颜色,想到一道神奇的‘天空龙’. 于是觉得此题可做. 那好了. 于是切掉,还拿了一个暴力对拍.疯狂A. 啊dfs慢的要死了 T2一眼 ...

  6. 接口Interface解耦的理解

    定义一个接口 磁盘 interface Disk(){   void save(File file);   } U盘和硬盘都是磁盘,都实现这个接口 class UDisk implement Disk ...

  7. Axure教程:如何使用动态面板?动态面板功能详解

    写了几个Axure教程之后发现,可能教程的起点有些高了,过分的去讲效果的实现,而忽略了axure功能以及基础元件的使用,那么从这个教程开始,把这些逐渐的展开讲解. 关于Axure动态面板 动态面板是a ...

  8. 02_springmvc处理器映射器和适配器(补充)

    一.非注解的处理器映射器 HandlerMapping 负责根据request请求找到对应的Handler处理器及Interceptor拦截器,将它们封装在HandlerExecutionChain ...

  9. Python学习day03 - Python基础(1)

    1. 执行Python程序的两种方式 (1)交互式(Jupyter) 优点:运行一句执行一句 缺点:关闭即消失# (2)命令行式(pycharm) 优点:可以一直保存 缺点:全部写完才能调试bug虽然 ...

  10. utils03_将本地仓库推送到gitHub的2种方式

    1.使用ssh连接方式 创建一个新的仓库 复制SSH 配置连接属性 完成推送 刷新hdhRepository2仓库 2.使用HTTPS连接方式 创建一个新的仓库 复制HTTPS 配置连接属性 第一次推 ...