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. dmesg命令详解

    基础命令学习目录 http://linux.cn/article-3587-1.html dmesg 命令的使用范例 下面我们展示一些最负盛名的‘dmesg’命令工具以及其实际使用举例.‘dmesg’ ...

  2. Team Member Introduction and Division of Work

    Team leader Name:宋天舒 Student Number:12061166 Interested In: Information safety. Responsible For: Des ...

  3. 除了C语言,C++······竟然还有Z语言?

    只能说自己见识短,头一次听说Z语言.先普及一下吧: Z语言是由牛津大学程序设计研究小组开发的一种形式语言,它是一种以一阶谓词演算为主要理论基础的规约语言,是一种功能性语言.Z语言是将事物的状态和行为用 ...

  4. Beta Scrum Day 2 — 听说

    听说

  5. 超实用 1 ArrayList 链表

    package ArrayList链表; import java.util.*; public class kk1 { /** * 作者:Mr.Fan * 功能:记住ArrayList链表 */ pu ...

  6. Java第一天——环境变量的配置与破解myeclipse2013

    一.jdk环境变量的配置 1.下载JDK并安装(官网JavaSE,64位(具体看电脑是多少位的))官网http://www.oracle.com/technetwork/java/javase/dow ...

  7. 标头 header()函数的用法

    头 (header) 是服务器以 HTTP 协议传 HTML 资料到浏览器前所送出的字串,在标头与 HTML 文件之间尚需空一行分隔. 范例一: 本例使浏览器重定向到 PHP 的官方网站. <? ...

  8. 转 js事件探秘

    Javascript中的事件,可以和html交互. 事件流IE&Opera:事件冒泡其他浏览器: 事件捕获 事件冒泡:事件由最具体的元素(文档中嵌套层次最深的那个节点)接收,然后逐级向上传播至 ...

  9. 带复杂类的list,list<class>前台往后台传输

    1.前台 $("#applyGoods").click(function(){ var usid=$(this).next().text(); var aid=$(this).ne ...

  10. Gulp插件笔记

    初次接触Gulp是出于网页模块化的需要,用过之后发现这个任务管理工具有很多实用的插件,意外地好用,于是打算写下这篇笔记把用到的Gulp插件记录一下.至于想了解Gulp基本用法的同学可以去Gulp官网查 ...