Writing CodeTime Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uDescription
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
Input3 3 3 100 1 1 1Output10Input3 6 5 1000000007 1 2 3Output0Input3 5 6 11 1 2 1Output0
题意:这题的题意真的是相当难懂,完全没有看懂,而且网上也没有找到题意解释,于是看了看别人的代码,总算知道了这道题是要我们干嘛了。
有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; }

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

478

被折叠的 条评论
为什么被折叠?



