标签:codeforces
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.
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.
Print a single integer — the answer to the problem modulo mod.
3 3 3 100 1 1 1
10
3 6 5 1000000007 1 2 3
0
3 5 6 11 1 2 1
0
题意:这题的题意真的是相当难懂,完全没有看懂,而且网上也没有找到题意解释,于是看了看别人的代码,总算知道了这道题是要我们干嘛了。
有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b,给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下,我们有几种选择方法
思路:看懂了题意之后就是一个完全背包题了
#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <bitset> #include <algorithm> #include <climits> using namespace std; #define LS 2*i #define RS 2*i+1 #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define LL long long #define N 205 #define MOD 19999997 #define INF 0x3f3f3f3f #define EXP 1e-8 const double Pi = acos(-1.0); int n,m,b,mod; int a[505]; LL dp[505][505],ans; int main() { int i,j,k; cin>>n>>m>>b>>mod; UP(i,1,n) cin>>a[i]; dp[0][0] = 1; UP(i,1,n) { UP(k,1,m) { UP(j,a[i],b) { dp[k][j]+=dp[k-1][j-a[i]]; dp[k][j]%=mod; } } } ans = 0; UP(i,0,b) { ans+=dp[m][i]; ans%=mod; } cout<<ans<<endl; return 0; }
Codeforces544C:Writing Code(完全背包)
标签:codeforces
原文地址:http://blog.csdn.net/libin56842/article/details/45743673