Codeforces 544C Writing Code【二维完全背包】
来源:互联网 发布:淘宝直播比较红的主播 编辑:程序博客网 时间:2024/05/02 01:25
Programmers working on a large project have just received a task to write exactlym lines of code. There are n programmers working on a project, the i-th of them makes exactlyai bugs in every line of code that he writes.
Let's call a sequence of non-negative integers v1, v2, ..., vn aplan, 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 writesv2 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 plangood, if all the written lines of the task contain at mostb 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 integermod.
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 integersa1, 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个程序员,一个程序员(编号为i)写一行代码会有Ai个bug.目的是完成一个M行的程序。
第i个程序员会写Vi行代码,对应就会出现Vi*Ai个Bug.
问将这个M行的程序写完之后,Bug数量不超过b个的分配方案数。
思路:
题目读懂之后,很显然的一个完全背包。
设定dp【i】【j】表示一共写了i行代码,一共写出来了j个Bug的方案数。
那么很简单的递推方程:dp【i】【j】=dp【i-1】【j-Ai】;
那么ans=Σdp【m】【i】(0<=i<=b)
Ac代码:
#include<stdio.h>#include<string.h>using namespace std;int dp[505][500*4];int main(){ int n,m,b,mod; while(~scanf("%d%d%d%d",&n,&m,&b,&mod)) { memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int z=0;z<n;z++) { int x; scanf("%d",&x); for(int i=1;i<=m;i++) { for(int j=x;j<=b;j++) { dp[i][j]+=dp[i-1][j-x]; dp[i][j]%=mod; } } } int ans=0; for(int i=0;i<=b;i++) { ans+=dp[m][i]; ans%=mod; } printf("%d\n",ans); }}
- Codeforces 544C Writing Code【二维完全背包】
- Codeforces 544C Writing Code(背包)
- CF544C:Writing Code(二维完全背包)
- codeforces #320 Writing Code (完全背包)
- 完全背包——Codeforces Round #302 (Div. 2) C. Writing Code
- codeforces 543A A. Writing Code(完全背包优化dp )
- [Codeforces 543A] Writing Code (完全背包DP)
- Codeforces544C:Writing Code(完全背包)
- codeforces 543A Writing Code(dp降维优化,完全背包思想)
- codefroces 543A Writing Code dp优化 完全背包
- Codeforces Div.301C Writing Code(简单dp)
- C. Writing Code(Codeforces Round #302(div2)
- Codeforces Round #302 (Div. 2)C. Writing Code--dp
- Codeforces Round #302 (Div. 2) C. Writing Code dp
- Codeforces#302-C. Writing Code-DP/滚动数组
- Codeforces Round #302 (Div. 2)-C. Writing Code
- CodeForces 543A-Writing Code
- hdu2159二维完全背包
- Android开发中selector状态选择器常用属性解析
- $.ajax()方法详解
- idea下gradle构建的spring项目dao层xml不识别问题
- Python学习笔记(14)-安装第三方模块
- angular中的ng-container标签
- Codeforces 544C Writing Code【二维完全背包】
- SharedPreferences用法
- java的语言基础二
- iOS 解决NSlog打印输出的的文字都是UTF-8格式
- greenDao 3.0基本使用
- 高效使用 Google
- CentOS 7.2.1511软件包下载
- 判断是否第一次进入app
- 各主流浏览器和服务器URL传参(GET方式)的最大处理能力说明