#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 5e4+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll dp[503][504],a[503],n,m,b,mod;
int main(){
while(cin>>n>>m>>b>>mod){
rep(i,1,n) a[i]=read();
memset(dp,0,sizeof dp);
dp[0][0]=1;
// rep(i,1,m){
// rep(j,0,b){
// dp[i][j]=dp[i-1][j]%mod;
// rep(k,1,n){
// if(j-a[k]>=0){
// dp[i][j]+=dp[i-1][j-a[k]];
// dp[i][j]%=mod;
// }
// }
// }
// }
rep(i,1,n){
rep(k,1,m){
rep(j,a[i],b){
dp[k][j]+=dp[k-1][j-a[i]];
dp[k][j]%=mod;
}
}
}
ll ans=0;
rep(i,0,b){
ans+=dp[m][i]%mod;
ans%=mod;
}
println(ans);
}
return 0;
}

UESTC - 1692 注意DP顺序的更多相关文章

  1. uestc 250 数位dp(水)

    /* 数位dp 水题 开两维一个记录长度,一个记录上一个数 */ #include<stdio.h> #include<string.h> #define N 13 int d ...

  2. UESTC - 1137 数位DP

    #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...

  3. dp题目列表

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  4. 别人整理的dp题目

    动态规划 动态规划 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322, 14 ...

  5. 别人整理的DP大全(转)

    动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...

  6. 插头DP专题

    建议入门的人先看cd琦的<基于连通性状态压缩的动态规划问题>.事半功倍. 插头DP其实是比较久以前听说的一个东西,当初是水了几道水题,最近打算温习一下,顺便看下能否入门之类. 插头DP建议 ...

  7. BZOJ 1079: [SCOI2008]着色方案(巧妙的dp)

    BZOJ 1079: [SCOI2008]着色方案(巧妙的dp) 题意:有\(n\)个木块排成一行,从左到右依次编号为\(1\)~\(n\).你有\(k\)种颜色的油漆,其中第\(i\)种颜色的油漆足 ...

  8. 『宝藏 状态压缩DP NOIP2017』

    宝藏(NOIP2017) Description 参与考古挖掘的小明得到了一份藏宝图,藏宝图上标出了 n 个深埋在地下的宝藏屋, 也给出了这 n 个宝藏屋之间可供开发的m 条道路和它们的长度. 小明决 ...

  9. P4890 Never·island(dp)

    P4890 Never·island 求门开的最小时间,其实也就是求门关的最大时间. 坐标这么大....显然坐标要离散化 离散化排序后,我们发现x轴被这些点划分成若干条线段$(l,r)$,并且有4种情 ...

随机推荐

  1. 在Python中操作谷歌浏览器

    在Python中使用谷歌浏览器,注意以下几点: 1.下载安装的谷歌浏览器Chrome和驱动chromedriver.exe要版本一致. 2.驱动chromedriver.exe要放在Chrome浏览器 ...

  2. CAP理论与HBase

    The short summary of the article is that CAP isn't "C, A, or P, choose two," but rather &q ...

  3. Palindromeness CodeChef - PALPROB

    传送门 分析 有中文题面所以就不写题目大意了 我们先建出回文树 然后根据fail信息建出一棵树 从根向下dfs,中间记录每一个len出现在哪个节点即可 代码 #include<iostream& ...

  4. Hyper-V和vmware在虚拟机中安装xen总结

    1. Hyper-V 在hyper-v中安装了ubuntu13.04,运行很好,使用起来的效果感觉比vmware要舒服.安装变异xen的内核也没有问题,可以正常的安装,update-grub之后也可以 ...

  5. Entity Framework快速入门--直接修改(简要介绍ObjectContext处理机制)

    在介绍Entity Framework的修改实体到数据库的方法之前呢,我们先简要的介绍一下ObjectContext的处理机制. 1.ObjectContext的处理机制 ObjectContext是 ...

  6. c++基础之向量Vector

    首先和string一样要在开头 #include <vector> #include <string> 和string一样,也算是一种容器,而且同属于STL(standard ...

  7. MongoDB整理笔记の指定命令和指定文件

    MongoDB shell 不仅仅是一个交互式的shell,它也支持执行指定javascript 文件,也支持执行指定的命令片断.有了这个特性,就可以将MongoDB 与linux shell 完美结 ...

  8. delphi 获取windows任务栏的高度

    function GetWinTrayWnd: Integer; // 获取windows任务栏高度 var TrayWnd: HWnd; //任务栏句柄 Rec : TRect; begin Tra ...

  9. .net 序列化 与反序列化 Serializable

    序列化:序列化指的是 将对象 通过流的方式 保存为一个文件. 反序列化则是将该文件还原成 对象的过程. 序列化的作用:序列化可以跨语言跨平台 传输数据,将某一对象序列化成通用的文件格式在进行传输. 比 ...

  10. 初学reactNative遇到的问题总结

    1.undefined is not an object (evaluating '_react3.default.PropTypes.shape') Navigator已经不再react nativ ...