题目描述

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 .

输入输出样例

输入样例#1:
复制

3 3 3 100
1 1 1
输出样例#1: 复制

10
输入样例#2: 复制

3 6 5 1000000007
1 2 3
输出样例#2: 复制

0
输入样例#3: 复制

3 5 6 11
1 2 1
输出样例#3: 复制

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的更多相关文章

  1. [CF543A]/[CF544C]Writing Code

    [CF543A]/[CF544C]Writing Code 题目大意: 有\(n\)种物品,每种物品分别要\(c_i\)的代价,每个物品有\(1\)的体积,每个物品可以选多个,代价不能超过\(b\), ...

  2. 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 ...

  3. 完全背包 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][ ...

  4. (完全背包)Writing Code -- Codeforce 544C

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=99951#problem/C  (zznu14) Writing Code  Writin ...

  5. 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 ...

  6. CodeForces 543A - Writing Code DP 完全背包

    有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b, 给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下, 我们有几种选择方法思路:看懂了题意之后 ...

  7. Code Forces 543A Writing Code

    题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...

  8. A. Writing Code 完全背包

    http://codeforces.com/contest/543/problem/A 一开始这题用了多重背包做,结果有后效性. 就是如果6,这样拆分成 1 + 2 + 3的,那么能产生3的就有两种情 ...

  9. Codeforces 543A Writing Code

    http://codeforces.com/problemset/problem/543/A 题目大意:n个人,一共要写m行程序,每个程序员每行出现的bug数为ai,要求整个程序出现的bug数不超过b ...

随机推荐

  1. 【学习笔记】第六章 python核心技术与实践--深入浅出字符串

    [第五章]思考题答案,仅供参考: 思考题1:第一种方法更快,原因就是{}不需要去调用相关的函数: 思考题2:用列表作为key在这里是不被允许的,因为列表是一个动态变化的数据结构,字典当中的key要求是 ...

  2. linux下安装pip(centos)

    centos系统中自带python2.7.5但是却没有pip工具 直接yum install pip会提示没有这个包 解决方案: 需要先安装扩展源EPEL. EPEL(http://fedorapro ...

  3. TCP通信 -C/S中的Socket与ServerSocket

    客户端类:Socket类 TCP通信的客户端:向服务器发送连接请求,给服务器发送数据,读取服务器的数据,两次IO流 java.lang.Object 继承者 java.net.Socket 构造方法: ...

  4. springmvc(二)

    请求信息转换 异步发送表单数据到JavaBean,并响应JSON文本返回 操作步骤:(1)加入Jackson2或fastjson框架包,springmvc默认支持Jackon2,不需要做任何操作,而f ...

  5. java8 base64使用

    java 1.8中引入了Base64,不在需要引入第三方库就可以使用base64了. 在需要用到base64进行加密解密的时候就可以使用了 String text = "base64 in ...

  6. 玩转 SpringBoot 2 之整合 JWT 上篇

    前言 该文主要带你了解什么是 JWT,以及JWT 定义和先关概念的介绍,并通过简单Demo 带你了解如何使用 SpringBoot 2 整合 JWT. 介绍前在这里我们来探讨一下如何学习一门新的技术, ...

  7. MapReduce案例-好友推荐

    用过各种社交平台(如QQ.微博.朋友网等等)的小伙伴应该都知道有一个叫 "可能认识" 或者 "好友推荐" 的功能(如下图).它的算法主要是根据你们之间的共同好友 ...

  8. MongoDB 学习笔记之 手动预先分片

    手动预先分片: 目的:手动预先分片是为了防止未来chunk的移动,减少IO. sh.shardCollection("shop.users",{"userId" ...

  9. Spring入门(十五):使用Spring JDBC操作数据库

    在本系列的之前博客中,我们从没有讲解过操作数据库的方法,但是在实际的工作中,几乎所有的系统都离不开数据的持久化,所以掌握操作数据库的使用方法就非常重要. 在Spring中,操作数据库有很多种方法,我们 ...

  10. CSS实现带箭头的提示框

    我们在很多UI框架中看到带箭头的提示框,感觉挺漂亮,但是之前一直不知道其原理,今天网上找了些资料算是弄清楚原理了: 先上效果图: 原理分析: 上面的箭头有没有觉得很像一个三角形,是的,它就是三角形:只 ...