题目描述

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. 如何在spingboot项目中自定义自己的配置

    在实际开发中,为了方便我们常常会考虑把配置文件的某一类配置映射到配置类上,方便spring容器加载,实现方法如下: 1. 书写配置文件信息:书写某一类特定字段开头的配置信息,例如在yml配置文件中可以 ...

  2. 基于 VMware 的超融合, 解析 vSAN 与 SmartX ZBS 的优劣差异

    在企业级IT领域从业多年,最近越来越多地听到圈内人谈论起超融合技术的种种好处.的确,超融合技术已越来越走向成熟,带来的价值也逐渐凸显.它可靠性高,资源消耗低,尤其是运维部署非常便捷.在企业基础架构领域 ...

  3. 小白专场-是否同一颗二叉搜索树-python语言实现

    目录 一.二叉搜索树的相同判断 二.问题引入 三.举例分析 四.方法探讨 4.1 中序遍历 4.2 层序遍历 4.3 先序遍历 4.4 后序遍历 五.总结 六.代码实现 一.二叉搜索树的相同判断 二叉 ...

  4. .NET Conf 2019 大会上发布.NET Core 3.0

    北京时间今天凌晨如期在.NET Conf 上发布.NET Core 3.0,Keynotes 由Scott Hunter 主演,主要围绕.NET Core 3.0的新特性和社区展开. 多功能性是.Ne ...

  5. oracle 11g 下载安装 使用记录

    Oracle 11g 使用记录 1.下载oracle快捷安装版:   (1)下载连接:https://pan.baidu.com/s/1ClC0hQepmTw2lSJ2ODtL7g 无提取码 (2)去 ...

  6. 运用 CSS in JS 实现模块化

    一.什么是 CSS in JS 上图来源:https://2019.stateofcss.com/technologies/ CSS in JS 是2014年推出的一种设计模式,它的核心思想是把 CS ...

  7. Centos 7 配置tomcat服务器

    1.首先查看当前系统版本 uname -a 2.安装之前查看系统是否安装了java rpm -qa |grep java rpm -qa |grep jdk rpm -qa |grep gcj 如果没 ...

  8. JavaSE知识点总结(一)

    第一章 课程介绍第二章 java语言概述 课时2:作业 1.常用软件分为那两类? 系统软件 应用软件 2.人机交互的两种方式是哪两种? 图形化界面 代码行命令 课时3:作业 1.java语言的特性有哪 ...

  9. Scrapy项目 - 数据简析 - 实现腾讯网站社会招聘信息爬取的爬虫设计

    一.数据分析截图 本例实验,使用Weka 3.7对腾讯招聘官网中网页上所罗列的招聘信息,如:其中的职位名称.链接.职位类别.人数.地点和发布时间等信息进行数据分析,详见如下图:   图1-1 Weka ...

  10. eclipse与hadoop集成,运行wordCount1

    搭好了hadoop集群之后,就该使用它了 第一步:下载hadoop eclipse的插件,将它放到eclipse\plugins的目录下,然后重启eclipse,点击windows->show ...