首页 > 其他分享 >Codeforces Round #302 (Div. 2)-C. Writing Code

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

时间:2023-06-12 17:33:58浏览次数:41  
标签:task 302 lines Codeforces number Code maxn input dp


原题链接


C. Writing Code



time limit per test



memory limit per test



input



output



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

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

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





dp[i][j]表示写了i行,有j个bug的种数,遍历n个程序员的bug数num[k], dp[i][j] += dp[i-1][j-num[k]]


#include <bits/stdc++.h>
#define maxn 5005
using namespace std;
typedef long long ll;

ll dp[maxn][maxn];
bool vis[maxn][maxn];
int main(){
//	freopen("in.txt", "r", stdin);
	int n, m, b, MOD, a;
	scanf("%d%d%d%d", &n, &m, &b, &MOD);
	dp[0][0] = 1;
	vis[0][0] = true;
	ll ans = 0;
	for(int i = 0; i < n; i++){
		scanf("%d", &a);
		for(int j = 1; j <= m; j++)
		 for(int h = a; h <= b; h++){
		    if(vis[j-1][h-a]){
		    	vis[j][h] = true;
		    	(dp[j][h] += dp[j-1][h-a]) %= MOD;
		    }
		 }
	}
	for(int i = 0; i <= b; i++){
		(ans += dp[m][i]) %= MOD;
	}
	printf("%I64d\n", ans);
	return 0;
}





标签:task,302,lines,Codeforces,number,Code,maxn,input,dp
From: https://blog.51cto.com/u_16158872/6464277

相关文章