(完全背包)Writing Code -- Codeforce 544C
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=99951#problem/C (zznu14)
Writing Code
Time Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes.
Let's call a sequence of non-negative integers v1, v2, ..., vn a plan, if v1 + v2 + ... + vn = m. The programmers follow the plan like that: in the beginning the first programmer writes the first v1 lines of the given task, then the second programmer writes 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 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.
Input
The first line contains four integers n, m, b, mod (1 ≤ n, m ≤ 500, 0 ≤ b ≤ 500; 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 space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of bugs per line for each programmer.
Output
Print a single integer — the answer to the problem modulo mod.
Sample Input
3 3 3 100
1 1 1
10
3 6 5 1000000007
1 2 3
0
3 5 6 11
1 2 1
0 dp[i][j]代表的是 i 行代码有 j 个错误的总数
#include<stdio.h>
#include<string.h> #define N 550 int dp[N][N], a[N]; int main()
{
int n, m, b, MOD; while(scanf("%d%d%d%d", &n, &m, &b, &MOD)!=EOF)
{
int i, j, k, w, sum=; memset(dp, , sizeof(dp));
memset(a, , sizeof(a)); for(i=; i<n; i++)
scanf("%d", &a[i]); for(i=; i<=m; i++)
{
w = i*a[i];
if(w<=b) dp[i][w] = ;
} for(i=; i<n; i++)
for(j=; j<m; j++)
for(k=; k<=b; k++)
{
if(dp[j][k])
{
int x = j-, y = k + a[i];
if(y<=b)
{
dp[x][y] += dp[j][k];
dp[x][y] %= MOD;
}
}
} for(i=; i<=b; i++)
{
sum += dp[m][i];
sum %= MOD;
} printf("%d\n", sum);
}
return ;
}
(完全背包)Writing Code -- Codeforce 544C的更多相关文章
- 完全背包 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][ ...
- [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 简单dp
C. Writing Code Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/prob ...
- CodeForces 544C (Writing Code)(dp,完全背包)
题意:有n个程序员,要协作写完m行代码,最多出现b个bug,第i个程序员每写一行代码就会产生a[i]个bug,现在问,这n个人合作来写完这m行代码,有几种方案使得出的bug总数不超过b(题中要求总方案 ...
- 背包DP || Codeforces 544C Writing Code
程序员写bug的故事23333 题意:n个程序员,一共写m行程序,最多产生b个bug,问方案数 思路:f[i][j]表示写了i行,产生了j个bug的方案数,因为每个人都是可以独立的,所以i循环到n都做 ...
- CodeForces 543A - Writing Code DP 完全背包
有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b, 给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下, 我们有几种选择方法思路:看懂了题意之后 ...
- A. Writing Code 完全背包
http://codeforces.com/contest/543/problem/A 一开始这题用了多重背包做,结果有后效性. 就是如果6,这样拆分成 1 + 2 + 3的,那么能产生3的就有两种情 ...
- CF543A Writing Code
题目描述 Programmers working on a large project have just received a task to write exactly m m m lines o ...
随机推荐
- 【Linux系列】Ubuntu ping通,xshell无法连接
现象描述:Ubuntu能Ping通主机,主机也能ping通虚拟机.而且,虚拟机也能上网.只是xshell不能连接. 解决方案: 一:使用管理员身份 设置防火墙. 先查看一下防火墙状态 sudo ufw ...
- Jmeter分布测试
一.负载机为Linux Linux上安装Jmeter 1.Windows中jmeter整个安装目录copy至Linux /usr/local/autodeploy目录 ps.使用winSCP工具cop ...
- SpringMVC之controller篇1
概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Spring 2.5 又为 Spring MVC 引入了注解驱动功能.现在你无须让 Controller 继承任何接口,无需在 ...
- Win32消息循环机制等【转载】http://blog.csdn.net/u013777351/article/details/49522219
Dos的过程驱动与Windows的事件驱动 在讲本程序的消息循环之前,我想先谈一下Dos与Windows驱动机制的区别: DOS程序主要使用顺序的,过程驱动的程序设计方法.顺序的,过程驱动的程序有一个 ...
- 最大子序列(java版)
package com.algorithm.test; /** * 最大子序列 * @author LiFen * */ public class LargestSubsequence { publi ...
- JoyOI1391 走廊泼水节
一道另类生成树 原题链接 将输入的树的\(n-1\)条边按从小到大排序,然后\(Kruskal\)在生成该树的过程中计算新增边的总长. 当在连第\(i\)条边,设该边的两端点为\(x,y\),长度为\ ...
- linux学习第三天 (Linux就该这么学)
今天是学习的第三天,讲了很多命令,又赶上双11,网络经常波动,我经常掉线,没有听到多少,回头再看一下录播.我也写一下讲的命令吧,也加深一下命令的印象.第三章老师讲完了. ifconfig命令:输出信息 ...
- 最新Dashboard设计实例、技巧和资源集锦,视觉和功能两不误,妥妥的!
Dashboard设计,尽管设计师们叫法各不相同(例如:“数据面板设计”, “控制面板设计”, “仪表盘设计”或“后台界面设计”等等).但,此类设计的最终目都是力求以最直观.最简洁的方式呈现各种信息和 ...
- pom.xml如何引入项目jar包
<dependency> <groupId>com.jacob</groupId> <artifactId>jacob</artifactId&g ...
- [cmd]如何设置 Windows 默认命令行窗口大小和缓冲区大小
Windows 命令行 cmd 窗口系统默认的大小(80*40)对于现在的屏幕配置已经跟不上时代了,我们总是要把它改大些,而且缓冲区大小也想改得大大的.单纯的为当前的 Windows 命令行窗口修改显 ...