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; ...
随机推荐
- 类欧几里德算法(洛谷 P5170
#include <iostream> #include <cstdio> #include <queue> #include <algorithm> ...
- C++ Builder VCL库函数简介
C++ Builder VCL库函数简介 2002-07-05· · ··C++builder资源中心 1 2 3 下一页 一.BORLAND C++ BUILDER VCL的内存管理函数 1. Al ...
- css正則匹配、模糊匹配
//所有class包含font-red的p标签 p[class~="font-red"] {color: red;} [abc^="def"] 选择 abc 属 ...
- 解决git每次输入密码,设置gitlab、github默认push的用户名和密码
git ssh key配置&解决git每次输入密码 欢迎加入qq群(IT-程序猿-技术交流群):757345416 在使用git时,每次pull/push都需要输入密码,有时大大降低了我们 ...
- idea配置tomcat中war和war exploded的区别
是选择war还是war exploded 这里首先看一下他们两个的区别: war模式:将WEB工程以包的形式上传到服务器 :war exploded模式:将WEB工程以当前文件夹的位置关系上传到服务器 ...
- 《DSP using MATLAB》Problem 8.9
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 0617Python-介绍、三种运行方式、变量、标识符和关键字、获取属性
一.什么是自动化测试? 1.定义 自动:让机器自己动,就是自动 自动化:让机器按照人类的要求,把软件的所有功能遍历一遍 2.传统测试和自动化测试的区别 传统测试:繁琐.机械.门槛低.工资低 自动化测试 ...
- Python GUI文本编辑器
使用Python编写一个简单的文本编辑器,需要展示一个用户界面,功能包括打开.保存文本文件. 使用tkinter库来编写GUI. #简单GUI文本编辑器 from tkinter import * f ...
- <每日一题>题目13:列表的简单问题
''' 分析: python赋值是通过指针来进行的. 很显然第一.三.四次调用都指向同一个列表,并未完成清空, 第二次调用只是指向了另一个列表,也未完成清空,很显然结果是累计的 结果: [0, 1] ...
- ubuntu与xshell连接不起来: