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 ...
随机推荐
- HDFS之Qurom Journal Manager(QJM)实现机制分析
前言 1.1背景 自从hadoop2版本开始,社区引入了NameNode高可用方案.NameNode主从节点间需要同步操作日志来达到主从节点元数据一致.最初业界均通过NFS来实现日志同步,大家之所以选 ...
- soap get/post请求
pom.xml依赖: <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactI ...
- 以商品超卖为例讲解Redis分布式锁
本案例主要讲解Redis实现分布式锁的两种实现方式:Jedis实现.Redisson实现.网上关于这方面讲解太多了,Van自认为文笔没他们好,还是用示例代码说明. 一.jedis 实现 该方案只考虑R ...
- 中国知网(CNKI)验证码识别
中国知网(CNKI)是最重要的中文学术资源数据库,收录绝大多数中文学术刊物.我们可以检索论文,也可以导出检索结果前6000条论文的题录数据. 在CNKI检索结果翻页10次以上,用户需要手动输入验证码才 ...
- Qt信号槽-原理分析
目录 一.问题 二.Moc 1.变量 2.Q_OBJECT展开后的函数声明 3.自定义信号 三.connect 四.信号触发 1.直连 2.队列连接 五.总结 六.推荐阅读 一.问题 学习Qt有一段时 ...
- 20 (OC)* GCD、NSOperation、NSThread。多线程
多线程编程技术的优缺点比较 NSThread (抽象层次:低) 优点:轻量级,简单易用,可以直接操作线程对象 缺点: 需要自己管理线程的生命周期,线程同步.线程同步对数据的加锁会有一定的系统开销. C ...
- [C++] 类的设计(2)——拷贝控制(1)
1.一个类通过定义五种特殊的成员函数来控制此类型对象的拷贝.移动.赋值和销毁:拷贝构造函数.拷贝赋值运算符.移动构造函数.移动赋值运算符和析构函数.(拷贝.移动.析构) 2.拷贝和移动构造函数定义 ...
- WebApi简介
简单创建.NET Core WebApi:https://www.cnblogs.com/yanbigfeg/p/9197375.html 登陆验证四种方式:https://www.cnblogs.c ...
- Android adb shell am 命令学习(1)
am:activity manager 启动Activity,打开或关闭进程,发送广播等操作 为什么学习: 主要应用部分,后台启动对应的package的Activity adb shell am st ...
- 为博客添加 Gitalk 评论插件
背景 Disqus需要翻墙才能正常使用 畅言有广告 2种评论系统都很难统一管理 优化 使用Gitalk评论插件 , gitalk 使用 Github 帐号登录,界面干净整洁,支持 MarkDown语法 ...