CodeForces 543A - Writing Code DP 完全背包
有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b,
给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下,
我们有几种选择方法思路:看懂了题意之后就是一个完全背包题了
定义dp[ i ][ j ][ k ] 表示前 i 个程序员,已经写了 j 行代码,
已经产生了 k 个 bugs 。
根据题意,得知第 i 个程序员会写 r 行代码,那么相当于
dp[ i ][ j ][ k ] += dp[i - 1][j - r][k - ra[ i ]]
Source Code:
/*************************************************************************
> File Name: code03.cpp
> Author: Jeremy Wu
> Created Time: Sun 31 May 2015 02:37:07 PM CST
************************************************************************/ #include <iostream> using namespace std; const int N = ;
int a[N];
int dp[][N][N]; int main () {
int i, j, k, l, m, n, bl, bugs, md; cin >> n >> bl >> bugs >> md;
for (i = ; i < n; ++i) cin >> a[i];
dp[][][] = ; for (int it = ; it <= n; ++it) {
i = it & ;
for (j = ; j <= bl; ++j) {
for (k = ; k <= bugs; ++k) {
dp[i][j][k] = dp[i ^ ][j][k];
if (j > && k >= a[it - ]) {
dp[i][j][k] += dp[i][j - ][k - a[it - ]];
}
while (dp[i][j][k] >= md) {
dp[i][j][k] -= md;
}
}
}
} int ans = ;
for (i = ; i <= bugs; ++i) {
ans += dp[n & ][bl][i];
while (ans >= md) {
ans -= md;
}
}
cout << ans << endl; return ;
}
CodeForces 543A - Writing Code DP 完全背包的更多相关文章
- CodeForces 544C (Writing Code)(dp,完全背包)
题意:有n个程序员,要协作写完m行代码,最多出现b个bug,第i个程序员每写一行代码就会产生a[i]个bug,现在问,这n个人合作来写完这m行代码,有几种方案使得出的bug总数不超过b(题中要求总方案 ...
- Codeforces 543A Writing Code
http://codeforces.com/problemset/problem/543/A 题目大意:n个人,一共要写m行程序,每个程序员每行出现的bug数为ai,要求整个程序出现的bug数不超过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 ...
- 背包DP || Codeforces 544C Writing Code
程序员写bug的故事23333 题意:n个程序员,一共写m行程序,最多产生b个bug,问方案数 思路:f[i][j]表示写了i行,产生了j个bug的方案数,因为每个人都是可以独立的,所以i循环到n都做 ...
- Code Forces 543A Writing Code
题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...
- 543A - Writing Code(二维动态规划)
题意:现在要写m行代码,总共有n个文件,现在给出第i个文件每行会出现v[i]个bug,问你在bug少于b的条件下有多少种安排 分析:定义dp[i][j][k],i个文件,用了j行代码,有k个bug 状 ...
- Codeforces 1197E Culture Code DP
题意:你有n个俄罗斯套娃,已知每个套娃的容积和体积,问有多少个子集满足以下条件: 1:这个子集是一个极大子集,即不能再添加其它的套娃到这个子集里. 2:子集的套娃之间的间隙和最小. 思路1:线段树优化 ...
- 完全背包 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][ ...
- 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 ...
随机推荐
- PHP学习(变量)
PHP学习(变量) 1. PHP属于松散类型,创建变量时不用指定类型. 2.变量命名规范: 1)第一个字符必须是$ 2)$后的第一个字符必须是 字母 或 下划线 3)其他字符可以是 字母, 数字, 下 ...
- HTML+CSS笔记 CSS中级 颜色&长度值
颜色值 在网页中的颜色设置是非常重要,有字体颜色(color).背景颜色(background-color).边框颜色(border)等,设置颜色的方法也有很多种: 1.英文命令颜色 语法: p{co ...
- leetcode第一刷_Construct Binary Tree from Inorder and Postorder Traversal
这道题是为数不多的感觉在读本科的时候见过的问题. 人工构造的过程是如何呢.兴许遍历最后一个节点一定是整棵树的根节点.从中序遍历中查找到这个元素,就能够把树分为两颗子树,这个元素左側的递归构造左子树,右 ...
- hdu 3966 Aragorn's Story(树链剖分+树状数组)
pid=3966" target="_blank" style="">题目链接:hdu 3966 Aragorn's Story 题目大意:给定 ...
- cocos2d基础入门
HelloCpp中Classes目录下放开发者自己的类: win32:平台相关,coco2d已默认创建:coco2d-x目录下,samples/cpp/HelloCpp/(工程根目录)图片放置位置:根 ...
- 【在网页中获取截图数据】Chrome和Firefox下的实战经验
[转载自我在segmentfault的专栏:https://segmentfault.com/a/1190000004584071] 最近在实现一个功能,需求如下: 前提:当前页面无弹窗 页面任意位置 ...
- Jquery调用webService的四种方法 转载-记录
我总结几个关键点 1. 服务必须声明为ScriptService(否则会出现下面的问题) 2.服务的方法不需要任何更改,保持原状 3.客户端用jquery的.ajax方法来调用 3.1 type必须是 ...
- 杭电oj find your present (2)
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...
- 查看Oracle有哪些表或者视图
转自:http://www.2cto.com/database/201211/167577.html 1.查询当前用户下,有哪些表 Sql代码 SELECT * FROM user_tables ...
- [LeetCode]题解(python):020-Valid Parentheses
题目来源: https://leetcode.com/problems/valid-parentheses/ 题意分析: 这道题输入一段只包括括号的字符串,判断这个字符串是否已经配对.配对的规则是,每 ...