Writing Code

Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 543A

Description

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.

Sample Input

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

 1 #include<stdio.h>
 2 #include<string.h>
 3
 4 int main()
 5 {
 6     int i,j,k;
 7     int n,m,b,mod,dp[505][505],a[505];
 8     memset(dp,0,sizeof(dp));
 9     scanf("%d %d %d %d",&n,&m,&b,&mod);
10
11     for(i=1;i<=n;i++)
12         scanf("%d",&a[i]);
13     dp[0][0]=1;
14     for(i=1;i<=n;i++)
15     {
16         for(j=0;j<m;j++)
17         {
18             for(k=0;k<=b-a[i];k++)
19             {
20                 dp[j+1][k+a[i]]=dp[j][k]+dp[j+1][k+a[i]];
21                 dp[j+1][k+a[i]]=dp[j+1][k+a[i]]%mod;
22             }
23         }
24     }
25     int ans=0;
26     for(k=0;k<=b;k++)
27     {
28         ans=ans+dp[m][k];
29         ans=ans%mod;
30     }
31     printf("%d\n",ans);
32     return 0;
33 }

时间: 2024-11-08 20:46:51

Writing Code的相关文章

Codeforces 543A Writing Code

A. Writing Code 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

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

题目传送门 1 /* 2 题意:n个程序员,每个人每行写a[i]个bug,现在写m行,最多出现b个bug,问可能的方案有几个 3 完全背包:dp[i][j][k] 表示i个人,j行,k个bug dp[0][0][0] = 1 表示不选择人的时候所有的bug的种类犯错误都只有一种 4 dp[i][j][k] += dp[i%2][j-1][k-a[i]]: 5 错误示范:dp[i][j][k] += dp[i-1][j-l][k-l*a[i]]; 其实要从上一行的状态推出,即少一行 6 内存限制,

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

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

CodeForces 543A - Writing Code DP 完全背包

有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b, 给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下, 我们有几种选择方法思路:看懂了题意之后就是一个完全背包题了 定义dp[ i ][ j ][ k ] 表示前 i 个程序员,已经写了 j 行代码, 已经产生了 k 个 bugs . 根据题意,得知第 i 个程序员会写 r 行代码,那么相当于 dp[ i ][ j ][ k ] += dp[i - 1][j - r][k - ra[ i ]

Codeforces544C:Writing Code(完全背包)

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

!CodeForces 543A Writing Code --DP--(三维dp,滚动数组)

题意:n个程序员一起写m行代码,第i个程序员每写一行有a[i]个bug,求总bug不超过b的分配方案有多少种 分析:这题很像完全背包,不过求的不是最大/最小bug数,求的是bug数小于上限的分配方案.所以这题要用三维dp dp[i][j][k]表示前i个个程序员总共写了j行代码产生了k个bug时的plan数,这题有两种转移:1)第i个程序员再写一行:2)换第i+1号程序员写 所以方程:dp[i][j][k]=dp[i-1][j][k]+dp[i][j-1][k-a[i]],注意:程序员可能一行都

What Every CLR Developer Must Know Before Writing Code

https://github.com/dotnet/coreclr/blob/master/Documentation/coding-guidelines/clr-code-guide.md

背包DP || Codeforces 544C Writing Code

程序员写bug的故事23333 题意:n个程序员,一共写m行程序,最多产生b个bug,问方案数 思路:f[i][j]表示写了i行,产生了j个bug的方案数,因为每个人都是可以独立的,所以i循环到n都做一遍 f[i][j] += f[i-1][j-a[i]] 在前一行  i 的 a[i] 个bug还没有写上去的情况数 #include <iostream> #include <cstdio> #include <algorithm> using namespace std

Become a Better Developer: 3 Ways Writing Will Expand Your Mind, Improve Your Code and Grow Your Career

Become a Better Developer: 3 Ways Writing Will Expand Your Mind, Improve Your Code and Grow Your Career September 10, 2013 Oliver White No comments inShare A long time ago, in a single-window basement far, far away- Since the dawn of time, content ma