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 ...
随机推荐
- rpyc + plumbum 实现远程调用执行shell脚本
rpyc可以很方便实现远程方法调用, 而plumbum则可以实现在python中类似shell的方式编码: 具体实现代码如下: Server.py import rpyc from rpyc.util ...
- Python Flask高级编程之RESTFul API前后端分离精讲 (网盘免费分享)
Python Flask高级编程之RESTFul API前后端分离精讲 (免费分享) 点击链接或搜索QQ号直接加群获取其它资料: 链接:https://pan.baidu.com/s/12eKrJK ...
- Flink 从 0 到 1 学习 —— Flink 配置文件详解
前面文章我们已经知道 Flink 是什么东西了,安装好 Flink 后,我们再来看下安装路径下的配置文件吧. 安装目录下主要有 flink-conf.yaml 配置.日志的配置文件.zk 配置.Fli ...
- TestNG(七)组测试
package com.course.testng.groups; import org.testng.annotations.AfterGroups; import org.testng.annot ...
- Day 25 网络基础
1:网络的重要性: 所有的系统都有网络! 我们的生活已经离不开网络. 运维生涯50%的生产故障都是网络故障! 2:教室这么多的电脑如何上网的? 网卡(mac地址) 有线(双绞线传播电信号)双向,同时收 ...
- 验证fstab文件修改是否正确
/etc/fstab文件是系统启动时要挂载点文件系统. 如果fstab文件配置错误,会导致系统无法正常启动. 最近我就是因为大意,在配置fstab重启服务器后,出现系统无法识别挂载点/opt/back ...
- 第六届蓝桥杯java b组第四题
第四题 两个整数做除法,有时会产生循环小数,其循环部分称为:循环节. 比如,11/13=6=>0.846153846153….. 其循环节为[846153] 共有6位. 下面的方法,可以求出循环 ...
- 词表征 2:word2vec、CBoW、Skip-Gram、Negative Sampling、Hierarchical Softmax
原文地址:https://www.jianshu.com/p/5a896955abf0 2)基于迭代的方法直接学 相较于基于SVD的方法直接捕获所有共现值的做法,基于迭代的方法一次只捕获一个窗口内的词 ...
- vue-router之路由元信息
路由元信息?(黑人问号脸???)是不是这么官方的解释很多人都会一脸懵?那么我们说meta,是不是很多人恍然大悟,因为在项目中用到或者看到过呢? 是的,路由元信息就是我们定义路由时配置的meta字段:那 ...
- 打印方案之web打印
前言: 前一段时间在工作中,遇到需要通过打印实现对报表或者工作流清单等事情时,都需要运用到打印功能,那么 ,这个时候你会怎么处理? 在这里,我们可以通过最简单的方式实现web打印功能,简单易懂,方便快 ...