dp[i][j] := 前i个数和为j的情况(mod p)

dp[i][j] 分两种情况 1.不选取第i个数 -> dp[i][j] = dp[i-1][j]

2.   选取第i个数 -> dp[i][j] = dp[i-1][t] ((t+a[i])%p==j)

(为什么很简单的题,思路也有了,比赛的时候就是写不对呢?)

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; typedef long long ll; ll a[1005];
ll dp[1005][1005];
const ll MOD = 1000000007; int main()
{
int t, n, p;
scanf("%d", &t);
while (t--) {
memset(dp, 0, sizeof dp);
scanf("%d%d", &n, &p); for (int i = 1; i <= n; ++i) {
scanf("%I64d", &a[i]);
}
dp[0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < p; ++j) {
int temp = (j - (a[i] % p) + p) % p;
dp[i][j] = (dp[i - 1][temp] + dp[i - 1][j]) % MOD;
}
}
printf("%I64d\n", dp[n][0]);
}
return 0;
} /**
Input:
78
4 2
1 2 3 4 Output:
8
*/

  

HDU 5464 ( Clarke and problem ) (dp)的更多相关文章

  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 1864 最大报销额(DP)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1864 题目: 最大报销额 Time Limit: 1000/1000 MS (Java/Others) ...

  4. HDU 2639 Bone Collector II (dp)

    题目链接 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took part in ...

  5. HDU 4562 守护雅典娜(dp)

    守护雅典娜 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submi ...

  6. hdu 1016 Prime Ring Problem(DFS)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. HDU 2522 A simple problem (模拟)

    题目链接 Problem Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^. 请大家编程帮助他. Input 第 ...

  8. HDU - 6199 gems gems gems (DP)

    有n(2e4)个宝石两个人轮流从左侧取宝石,Alice先手,首轮取1个或2个宝石,如果上一轮取了k个宝石,则这一轮只能取k或k+1个宝石.一旦不能再取宝石就结束.双方都希望自己拿到的宝石数比对方尽可能 ...

  9. dp hdu 5464 Clarke and problem

    Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned i ...

随机推荐

  1. js函数语法

    <script type="text/javascript">    //1 普通方法  /*   *  function 方法名(参数){   *   方法体   * ...

  2. secondarynamenode异常

    secondarynamenode异常 -- ::, ERROR org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode: Exception ...

  3. google 开放I/O源码

    在这款应用程序中谷歌对部分功能.API和设计架构进行了非常详细的阐述,其中包括碎片.程序加载.服务.广播.接收器.警告.通知.SQLite数据库.内容提供商.Action Bar.导航Drawer和G ...

  4. [CC150] Get all permutations of a string

    Problem: Compute all permutations of a string of unique characters. 此题用循环的方式不好做,下面是一种递归的思路: 把给的字符串看成 ...

  5. 升级mac中的系统之后,给PHP安装扩展常出现问题

    (1)在装mcrypt插件时报错,提示:mcrypt fatal error: 'php.h' file not found,然后又仔细操作了一次在输完phpize回车时就已经开始出错了,出错信息如下 ...

  6. PHP mysql_real_escape_string() 函数

    定义和用法 mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符. 下列字符受影响: \x00 \n \r \ ' " \x1a 如果成功, ...

  7. System.out.println(对象)

    class Person { private String name; private int age; public String getName() { return this.name; } p ...

  8. unity 导出 android安装包配置方案

    原地址:http://blog.csdn.net/u012085988/article/details/17393111 1.jdk本人安装的是win32版的(虽然系统是64位的.但听说装64位的导出 ...

  9. Bootstrap 貌似不错,先做一下记录

    Bootstrap 简洁.直观.强悍的前端开发框架,让web开发更迅速.简单. http://www.bootcss.com/

  10. POJ 3007 Organize Your Train part II(哈希链地址法)

    http://poj.org/problem?id=3007 题意 :给你一个字符串,让你无论从什么地方分割,把这个字符串分成两部分s1和s2,然后再求出s3和s4,让你进行组合,看能出来多少种不同的 ...