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. 微软职位内部推荐-ATG Engineer II

    微软近期Open的职位: ATG Engineer - GeneralistReady to work on some of the most advanced hardware on the pla ...

  2. custom event in javascript and jquery

    javascript: // add a eventListener document.addEventListener("abc", function(){alert('this ...

  3. struts2用了哪几种模式

    代理模式 责任连模式 ActionVacation 迭代模式

  4. 如何解决jenkins中shell脚本明明执行失败却不自行退出,且构建结果仍然显示success的问题??

    首先,需要明确shell命令执行结果$?为0或者非0仅能代表此执行语句是否顺利执行了,例如: 执行语句:adb connect 192.168.XX.XX 执行结果:unable to connect ...

  5. Nhibernate cookbook 3.0-翻译

    /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-ts ...

  6. django中外键关联表的查询随笔

    django中,如果一个数据库中的表之间有外键的话可以方便的通过一个表查询到其相关表的数据.如有下面三个model:class Blog(models.Model):    name = models ...

  7. 如何在Ubuntu Unity上修改应用程序图标

    转自如何在Ubuntu Unity上修改应用程序图标 这篇文章将教大家在Ubuntu Unity上修改应用程序图标,这个教程适合于Ubuntu 14.04, Ubuntu 13.10, Ubuntu ...

  8. IOS ITunesConnect 修改开发商名称

    ItunesConnect→ManagerApps→应用→Contact Us

  9. jQuery.Validate自定义规程的使用案例

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. js设置radio选中

    在页面数据绑定时,经常会遇到给radio设置选中,以下是我写的js方法,经测试可以使用.欢迎拍砖 <html> <head> <script type="tex ...