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 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 test(s)

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<cstdio>
 2 #include<cstring>
 3 using namespace std;
 4
 5 int main()
 6 {
 7     int i,j,k;
 8     int p[505];
 9     int n,m,b,mod;
10     long long dp[505][505];
11     while(scanf("%d%d%d%d",&n,&m,&b,&mod)!=EOF)
12     {
13         memset(dp,0,sizeof(dp));
14         for(i=0;i<n;i++)
15             scanf("%d",&p[i]);
16         dp[0][0]=1;
17         for(i=0;i<n;i++)
18             for(j=1;j<=m;j++)
19                 for(k=p[i];k<=b;k++)
20                 {
21                     dp[j][k]+=dp[j-1][k-p[i]];
22                     dp[j][k]%=mod;
23                 }
24         int ans=0;
25         for(i=0;i<=b;i++)
26         {
27             ans+=dp[m][i];
28             ans%=mod;
29         }
30         printf("%d\n",ans);
31     }
32     return 0;
33 }
时间: 2024-08-11 22:14:00

Codeforces 543A Writing Code的相关文章

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 ]

!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]],注意:程序员可能一行都

背包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

完全背包 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 内存限制,

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 programmer

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

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 完全背包

安排n个人写m行代码,每个人每行会出a[i]个bug,求最多出现b个bug的方案数. 一个二维的完全背包,每个人有两个状态:写j行代码出k个bug dp[i][j][k] 前i个程序员写钱j行出现k个bug的方案数. dp[i][j][k] = dp[i][j-1][k-a[i]] + dp[i-1][j][k]; 注意这里数组会超内存,需要用滚动数组. #include <iostream> using namespace std; int n, m, b; long long mod; l

【codeforces】ZeptoLab Code Rush 2015 E 跳跃表?

题意就是给n个数,围成一圈,就是1和n是相邻的,然后给一个数b,总和不超过b的一段连续的数可以组成一组,问最少可以将n个数分成几组. 可以将n个数后面再接n个数,就变成n+n个数,然后以每个数为开头的组最远能到哪也是很容易求的,O(n)维护个指针可以处理.把远的位置视为跳一步能到的吧,这样问题就转化为1到n中的第i个数至少到第n+i个数要跳多少次.这个如果是一般图的话,就是类似树上求k步的祖先在哪,可以用倍增法,n*log(n).但是这题图比较特殊,i<j的话,i跳到的下一点位置不会超过j跳到的