dp hdu 5464 Clarke and problem
Problem DescriptionClarke 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 answermodulo 109+7InputThe 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).OutputFor each testcase print a integer, the answer.Sample Input12 31 2Sample Output2Hint:
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的更多相关文章
- HDU 5464 Clarke and problem 动态规划
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5464 Clarke and problem Accepts: 130 Submissions: ...
- hdu 5464 Clarke and problem dp
Clarke and problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...
- 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个数 -> ...
- HDU 5464:Clarke and problem
Clarke and problem Accepts: 130 Submissions: 781 Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- 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思路差不 ...
- HDU 5628 Clarke and math——卷积,dp,组合
HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...
- [HDU 5293]Tree chain problem(树形dp+树链剖分)
[HDU 5293]Tree chain problem(树形dp+树链剖分) 题面 在一棵树中,给出若干条链和链的权值,求选取不相交的链使得权值和最大. 分析 考虑树形dp,dp[x]表示以x为子树 ...
- hdu 2993 MAX Average Problem(斜率DP入门题)
题目链接:hdu 2993 MAX Average Problem 题意: 给一个长度为 n 的序列,找出长度 >= k 的平均值最大的连续子序列. 题解: 这题是论文的原题,请参照2004集训 ...
- 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; ...
随机推荐
- 纵览轻量化卷积神经网络:SqueezeNet、MobileNet、ShuffleNet、Xception
近年提出的四个轻量化模型进行学习和对比,四个模型分别是:SqueezeNet.MobileNet.ShuffleNet.Xception. SqueezeNet https://arxiv.org/p ...
- 内核下枚举进程 (二)ZwQuerySystemInformation
说明: SYSTEM_INFORMATION_CLASS 的5号功能枚举进程信息.其是这个函数对应着ring3下的 NtQuerySystemInformation,但msdn上说win8以后ZwQu ...
- 深入浅出 Java Concurrency (28): 线程池 part 1 简介[转]
从这一节开始正式进入线程池的部分.其实整个体系已经拖了很长的时间,因此后面的章节会加快速度,甚至只是一个半成品或者简单化,以后有时间的慢慢补充.完善. 其实线程池是并发包里面很重要的一部分,在实际情况 ...
- Error-Idea:Process finished with exit code 1
ylbtech-Error-Idea:Process finished with exit code 1 1.返回顶部 1. log4j:WARN No appenders could be foun ...
- 02.vs插件 获取项目和解决方案路径
获取项目 解决方案路径 /// <summary> /// 获取并设置项目和解决方案绝对路径 /// </summary> /// <returns></re ...
- c++ STL使用
STL标准模板库,提供一些类似java集合类的数据结构容器.比如eque.list.vector.map 等.还提供一些支持这些容器的算法和遍历容器的迭代器. 使用方法 #include <io ...
- PAT甲级——A1091 Acute Stroke【30】
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- PKU--2184 Cow Exhibition (01背包)
题目http://poj.org/problem?id=2184 分析:给定N头牛,每头牛都有各自的Si和Fi 从这N头牛选出一定的数目,使得这些牛的 Si和Fi之和TS和TF都有TS>=0 F ...
- 如何使用Pig集成分词器来统计新闻词频?
散仙在上篇文章中,介绍过如何使用Pig来进行词频统计,整个流程呢,也是非常简单,只有短短5行代码搞定,这是由于Pig的内置函数TOKENIZE这个UDF封装了单词分割的核心流程,当然,我们的需求是各种 ...
- C开发系列-continue与break
break break使用场景 switch语句:退出整个switch语句 循环结构:退出整个循环语句 while循环 do while循环 for 循环 continue continue使用场景 ...