Codeforces544C:Writing Code(完全背包)
来源:互联网 发布:在windows上启动mysql 编辑:程序博客网 时间:2024/05/22 16:42
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 1001 1 1
10
3 6 5 10000000071 2 3
0
3 5 6 111 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-8const 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(完全背包)
- Codeforces544C:Writing Code
- codeforces #320 Writing Code (完全背包)
- CF544C:Writing Code(二维完全背包)
- codeforces 543A A. Writing Code(完全背包优化dp )
- [Codeforces 543A] Writing Code (完全背包DP)
- codefroces 543A Writing Code dp优化 完全背包
- Codeforces 544C Writing Code【二维完全背包】
- codeforces 543A Writing Code(dp降维优化,完全背包思想)
- 完全背包——Codeforces Round #302 (Div. 2) C. Writing Code
- codeforces543AWriting Code(完全背包)
- codeforces544C
- Codeforces 544C Writing Code(背包)
- Writing code is writing
- 《Writing clean code》读书笔记
- Writing Solid Code
- Writing clean code
- Writing Exception Code
- 经典的重定位代码
- CentOS 6.5下本地yum源与网络yum源的配置使用
- C++内存管理
- CMarkup的保存与读取
- WIN32串口编程详解(一)
- Codeforces544C:Writing Code(完全背包)
- druid项目实例
- hdu 4966 GGS-DDU(无固定根的最小树形图)
- 存储 key/value的hashtable
- Exe4j破解_Exe4j注册码
- WIN32串口编程详解(二)
- XDOJ 数独
- Cstring转char、string、int等数据类型的方法
- 监听密码框大小写提示