题意:

给你n个数,要求选一些数(可以不选),把它们加起来,使得和恰好是p的倍数(0也是p的倍数),求方案数。

- - 心好痛,又没想到动规

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int p[1005];
int dp[1005][1005];
const int inf = 0x3f3f3f3f;
int main()
{
int T,n,t;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&t);
memset(p,0,sizeof(p));
for(int i = 1; i <= n; i++)
{
scanf("%d",&p[i]);
p[i]=p[i]%t;
if(p[i] < 0)
p[i]=(p[i]+t)%t;
}
memset(dp,0,sizeof(dp));
dp[1][0] = 1;
dp[1][p[1]] += 1; for(int i = 2; i <= n; i++)
{
for(int j = 0; j < t; j++)
{
dp[i][j] += dp[i-1][j];
dp[i][j] %= mod;
dp[i][(j+p[i]) % t] += dp[i-1][j];
dp[i][(j+p[i]) % t] %= mod;
}
} printf("%d\n",dp[n][0] % mod);
}
return 0;
}

  

hdu 5464(dp)的更多相关文章

  1. hdu 5534(dp)

    Input The first line contains an integer T indicating the total number of test cases. Each test case ...

  2. HDU 5800 (DP)

    Problem To My Girlfriend (HDU 5800) 题目大意 给定一个由n个元素组成的序列,和s (n<=1000,s<=1000) 求 :   f (i,j,k,l, ...

  3. HDU 2571(dp)题解

    命运 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  4. Find a path HDU - 5492 (dp)

    Find a path Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. 饭卡 HDU - 2546(dp)

    电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够).所以大家 ...

  6. HDU 4489(DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4489 解题思路这里已经说的很清楚了: http://blog.csdn.net/bossup/article/d ...

  7. hdu 1024(dp)

    传送门:Max Sum Plus Plus 题意:从n个数中选出m段不相交的连续子段,求这个和最大. 分析:经典dp,dp[i][j][0]表示不取第i个数且前i个数分成j段达到的最优值,dp[i][ ...

  8. AreYouBusy HDU - 3535 (dp)

    AreYouBusy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. HDU 2577(DP)

    题意:要求一个字符串输入,按键盘的最少次数.有Caps Lock和Shift两种转换大小写输入的方式 思路:用dpa与dpb数组分别记录Caps Lock的开关状态,dpa表示不开,dpb表示开 代码 ...

随机推荐

  1. Linux 磁盘和文件管理系统 文件打包解压备份 VIM、VI编辑器

  2. Hangfire使用ApplicationInsigts监控

    起因 我司目前使用清真的ApplicationInsights(以下简称Ai)来做程序级监控.(Ai相关文档: https://azure.microsoft.com/zh-cn/services/a ...

  3. [翻译]现代java开发指南 第三部分

    现代java开发指南 第三部分 第三部分:Web开发 第一部分,第二部分,第三部分 =========================== 欢迎来到现代 Java 开发指南第三部分.在第一部分中,我们 ...

  4. Apache虚拟主机实战

    [root@localhost ~]# wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.32.tar.bz2  [root@localho ...

  5. hadoop2.6.0实践:A01 问题处理 DEPRECATED: Use of this script to execute hdfs command is deprecated.

    [hadoop@hadoop-master data]$ hadoop dfs -ls /DEPRECATED: Use of this script to execute hdfs command ...

  6. hadoop2.7.3+spark2.1.0+scala2.12.1环境搭建(2)安装hadoop

    一.依赖安装 安装JDK 二.文件准备 hadoop-2.7.3.tar.gz 2.2 下载地址 http://hadoop.apache.org/releases.html 三.工具准备 3.1 X ...

  7. python入门(5)使用文件编辑器编写代码并保存执行

    python入门(5)使用文件编辑器编写代码并保存执行 两款文本编辑器: 一个是Sublime Text,免费使用,但是不付费会弹出提示框: 一个是Notepad++,免费使用,有中文界面: 请注意, ...

  8. leetcode算法:Trim a Binar Search Tree

    Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that a ...

  9. memcached企业面试题

    面试题如下: 1.Memcached是什么,有什么作用?Memcached是一个开源的,高性能的内存绶存软件,从名称上看Mem就是内存的意思,而Cache就是缓存的意思. Memcached的作用:通 ...

  10. Java:Linux上java -jar xxx.jar命令执行jar包时出现Error: Invalid or corrupt jarfile xxx.jar解决方案

    背景: 从ftp上上传jar包到linux上,之后在linux上通过ftp命令下载jar包文件,开始执行Java-jar,一直提示错误:Error: Invalid or corrupt jarfil ...