CF543A Writing Code
题目描述
Programmers working on a large project have just received a task to write exactly m m m lines of code. There are n n n programmers working on a project, the i i i -th of them makes exactly ai a_{i} ai bugs in every line of code that he writes.
Let's call a sequence of non-negative integers v1,v2,...,vn v_{1},v_{2},...,v_{n} v1,v2,...,vn a plan, if v1+v2+...+vn=m v_{1}+v_{2}+...+v_{n}=m v1+v2+...+vn=m . The programmers follow the plan like that: in the beginning the first programmer writes the first v1 v_{1} v1 lines of the given task, then the second programmer writes v2 v_{2} 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 b 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 mod mod .
输入输出格式
输入格式:
The first line contains four integers n n n , m m m , b b b , mod mod mod ( 1<=n,m<=500 1<=n,m<=500 1<=n,m<=500 , 0<=b<=500 0<=b<=500 0<=b<=500 ; 1<=mod<=109+7 1<=mod<=10^{9}+7 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 n n space-separated integers a1,a2,...,an a_{1},a_{2},...,a_{n} a1,a2,...,an ( 0<=ai<=500 0<=a_{i}<=500 0<=ai<=500 ) — the number of bugs per line for each programmer.
输出格式:
Print a single integer — the answer to the problem modulo mod mod mod .
输入输出样例
3 5 6 11
1 2 1
0
设f[i][j][k]表示前i个人, 写了j行, 有k个bug的方案个数;
然后完全背包转移, 加上滚动数组。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
inline int read(){
int res = ;char ch=getchar();bool fl = ;
while(!isdigit(ch)){if(ch=='-')fl=;ch=getchar();}
while(isdigit(ch)){res=(res<<)+(res<<)+(ch^);ch=getchar();}
return fl?-res:res;
}
int n, m, b, mod;
int a[];
int f[][][];
int ans; int main()
{
n = read(), m = read(), b = read(), mod = read();
for (register int i = ; i <= n ; i ++) a[i] = read();
f[][][] = ;
for (register int i = ; i <= n ; i ++){
memset(f[i%], , sizeof f[i%]);
for (register int j = ; j <= m ; j ++){
for (register int k = ; k <= b ; k ++){
if (k >= a[i] and j >= )
f[i%][j][k] = f[i%][j-][k-a[i]] % mod;;
f[i%][j][k] = (f[i%][j][k] + f[(i-)%][j][k]) % mod;
}
}
}
for (register int i = ; i <= b ; i ++) ans = (ans + f[n%][m][i]) % mod;
printf("%d", ans % mod);
return ;
}
CF543A Writing Code的更多相关文章
- [CF543A]/[CF544C]Writing Code
[CF543A]/[CF544C]Writing Code 题目大意: 有\(n\)种物品,每种物品分别要\(c_i\)的代价,每个物品有\(1\)的体积,每个物品可以选多个,代价不能超过\(b\), ...
- Codeforces Round #302 (Div. 2).C. Writing Code (dp)
C. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard inp ...
- 完全背包 Codeforces Round #302 (Div. 2) C Writing Code
题目传送门 /* 题意:n个程序员,每个人每行写a[i]个bug,现在写m行,最多出现b个bug,问可能的方案有几个 完全背包:dp[i][j][k] 表示i个人,j行,k个bug dp[0][0][ ...
- (完全背包)Writing Code -- Codeforce 544C
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=99951#problem/C (zznu14) Writing Code Writin ...
- Codeforces Round #302 (Div. 2) C. Writing Code 简单dp
C. Writing Code Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/prob ...
- CodeForces 543A - Writing Code DP 完全背包
有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b, 给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下, 我们有几种选择方法思路:看懂了题意之后 ...
- Code Forces 543A Writing Code
题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...
- A. Writing Code 完全背包
http://codeforces.com/contest/543/problem/A 一开始这题用了多重背包做,结果有后效性. 就是如果6,这样拆分成 1 + 2 + 3的,那么能产生3的就有两种情 ...
- Codeforces 543A Writing Code
http://codeforces.com/problemset/problem/543/A 题目大意:n个人,一共要写m行程序,每个程序员每行出现的bug数为ai,要求整个程序出现的bug数不超过b ...
随机推荐
- 5.1、顺序队列(java实现)
1.实现代码 public class SeqQueue { private final int MaxSize = 8; private int rear; //队尾指针 private int f ...
- JVM性能监视
1,按照如下图步骤将-XX:PermSize及 -XX:MaxPermSize的值修改到足够小,故意造项目启动报错,我设置为32m.然后保存. 2.在IDE中启动tomcat的同时打开dos窗口,使用 ...
- Javaweb设置session过期时间
在Java Web开发中,Session为我们提供了很多方便,Session是由浏览器和服务器之间维护的.Session超时理解为:浏览器和服务器之间创建了一个Session,由于客户端长时间(休眠时 ...
- ios 把数组对象转成json字符串存起来
1第一步是我们获取数据源 一般我们都是从接口请求数据 NSArray *subColumnsArray = nil; NSDictionary *dict = [NSJSONSerialization ...
- django学之路01--环境安装和pycharm运行django项目
1. 环境安装 1).virtualenv安装 C:\Users\Administrator>pip install virtualenv Collecting virtualenv Using ...
- 控制执行流程之switch语句
switch语句,同时也是一种选择性语句,其根据整数表达式的值(整数选择因子)选择一段代码去执行.整数选择因子为int类型或者char类型.
- 007:CSS字体图标
目录 理论 一:字体图标 图片是有诸多优点的,但是缺点很明显,比如图片不但增加了总文件的大小,还增加了很多额外的"http请求",这都会大大降低网页的性能的.更重要的是图片不能很好 ...
- JS 延时函数
function sleep(delay) { var start = (new Date()).getTime(); while((new Date()).getTime() - start < ...
- Mysql学习笔记整理之数据库优化
数据库性能瓶颈的原因 数据库连接数 数据量大 硬件资源限制 数据性能优化方案 sql优化 2.缓存 3.建好索引 4.读写分离 5. 分库分表 慢日志查 ...
- 浅谈JavaScript的闭包原理
在一般的教程里,都谈到子作用域可以访问到父级作用域,进而访问到父级作用域中的变量,具体是如何实现的,就不得不提及到函数堆栈和执行上下文. 举个例子,一个简单的闭包: 首先,我们可以知道,examp ...