Codeforces 543A. Writing Code DP

本文探讨了一种特殊的代码编写场景,n位程序员需共同完成m行代码,每位程序员编写代码时会产生不同数量的BUG。任务是在确保总BUG数不超过限制的前提下,找出所有可行的代码分配方案,并提供了一个通过动态规划解决此问题的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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


题意:这题的题意真的是相当难懂,完全没有看懂,而且网上也没有找到题意解释,于是看了看别人的代码,总算知道了这道题是要我们干嘛了。
有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b,给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下,我们有几种选择方法
思路:看懂了题意之后就是一个完全背包题了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,b,mod;
int a[505],dp[505][505];
int main()
{
    while(~scanf("%d %d %d %d",&n,&m,&b,&mod))
    {
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++){
                for(int k=a[i];k<=b;k++){
                    dp[j][k]+=dp[j-1][k-a[i]];
                    dp[j][k]%=mod;
                }
            }
        }
        int sum=0;
        for(int i=0;i<=b;i++)
        {
            sum+=dp[m][i];
            sum%=mod;
        }
        printf("%d\n",sum);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值