Codeforces 543A. Writing Code DP

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


發佈了106 篇原創文章 · 獲贊 5 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章