Codeforces 544C Writing Code【二维完全背包】

来源:互联网 发布:淘宝直播比较红的主播 编辑:程序博客网 时间:2024/05/02 01:25

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 exactlym lines of code. There are n programmers working on a project, the i-th of them makes exactlyai bugs in every line of code that he writes.

Let's call a sequence of non-negative integers v1, v2, ..., vn aplan, 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 writesv2 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 plangood, if all the written lines of the task contain at mostb 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 integermod.

Input

The first line contains four integers n,m, b,mod (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 integersa1, 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 1001 1 1
Output
10
Input
3 6 5 10000000071 2 3
Output
0
Input
3 5 6 111 2 1
Output
0

题目大意:

现在一共有N个程序员,一个程序员(编号为i)写一行代码会有Ai个bug.目的是完成一个M行的程序。

第i个程序员会写Vi行代码,对应就会出现Vi*Ai个Bug.

问将这个M行的程序写完之后,Bug数量不超过b个的分配方案数。


思路:


题目读懂之后,很显然的一个完全背包。

设定dp【i】【j】表示一共写了i行代码,一共写出来了j个Bug的方案数。

那么很简单的递推方程:dp【i】【j】=dp【i-1】【j-Ai】;

那么ans=Σdp【m】【i】(0<=i<=b)


Ac代码:

#include<stdio.h>#include<string.h>using namespace std;int dp[505][500*4];int main(){    int n,m,b,mod;    while(~scanf("%d%d%d%d",&n,&m,&b,&mod))    {        memset(dp,0,sizeof(dp));        dp[0][0]=1;        for(int z=0;z<n;z++)        {            int x;            scanf("%d",&x);            for(int i=1;i<=m;i++)            {                for(int j=x;j<=b;j++)                {                dp[i][j]+=dp[i-1][j-x];                   dp[i][j]%=mod;                }            }        }        int ans=0;        for(int i=0;i<=b;i++)        {            ans+=dp[m][i];            ans%=mod;        }        printf("%d\n",ans);    }}







原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 河北发货一个柜到天津港口怎么办 家用潜水泵更换电容后压力小怎么办 无塔供水井水水位低了怎么办 应急部成立林场的专业灭火队怎么办 路由器我恢复出厂设置断网了怎么办 多囊卵巢综合症不来月经怎么办 天刀普通血战苍梧城没有太白怎么办 天涯明月刀把沈妄言打入水中怎么办 天涯明月刀刷本队友技能太花怎么办 手机收所有短信时显示被隐藏怎么办 div放图片多出的空白怎么办 我14岁射精让我记忆力差了怎么办 qq闪退聊天记录全没了怎么办 木瓜奇迹忘记升级过头转职了怎么办 孩子进入青春期什么坏事都干怎么办 母狗狗第一次来月经应该怎么办图 社保断了想补缴怎么办?这些要知道 换工作社保断了一个月怎么办 北京社保中间断了几个月怎么办 农保和社保都交了医保怎么办 如果交了社保结婚生孩子断了怎么办 南京社保中间断了几个月怎么办 mu大师等级技能点加点太慢怎么办 永恒纪元戒不是本职业套装石怎么办 全民奇迹忘记在哪个区了怎么办 全民奇迹安卓的忘记那个区了怎么办 大天使之剑h5所在服人少怎么办 买的裙子因为好看没有勇气穿怎么办 魅蓝s6锁屏密码忘了怎么办 u盘被占用不能安全弹出怎么办 洛克王国得到了魔攻巨蟹座怎么办 在育碧下载游戏下一半不下了怎么办 轩辕传奇单机版忘记哪个区了怎么办 登腾讯游戏动态密码啥意思怎么办 说了不该说的话别人不原谅怎么办 轩辕传奇手游金币用错了怎么办 神秘时代4法杖按键冲突怎么办 孕2个月发烧38度怎么办 不知道怀孕喝了止咳糖浆怎么办? 小孩刮头发的备皮刀割住手怎么办? 天梭手表里面的刻度掉了怎么办