Codeforces--106C--Buns(背包)
Time Limit: 2000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
Description
Lavrenty, a baker, is going to make several buns with stuffings and sell them.
Lavrenty has n grams of dough as well as
m different stuffing types. The stuffing types are numerated from 1 to
m. Lavrenty knows that he has
ai grams left of the
i-th stuffing. It takes exactly
bi grams of stuffing
i and ci grams of dough to cook a bun with the
i-th stuffing. Such bun can be sold for
di tugriks.
Also he can make buns without stuffings. Each of such buns requires
c0 grams of dough and it can be sold for
d0 tugriks. So Lavrenty can cook any number of buns with different stuffings or without it unless he runs out of dough and the stuffings. Lavrenty throws
away all excess material left after baking.
Find the maximum number of tugriks Lavrenty can earn.
Input
The first line contains 4 integers
n, m,
c0 and
d0 (1 ≤ n ≤ 1000,
1 ≤ m ≤ 10, 1 ≤ c0, d0 ≤ 100). Each
of the following m lines contains
4 integers. The i-th line contains numbers
ai,
bi,
ci and
di (1 ≤ ai, bi, ci, di ≤ 100).
Output
Print the only number — the maximum number of tugriks Lavrenty can earn.
Sample Input
10 2 2 1
7 3 2 100
12 3 1 10
241
100 1 25 50
15 5 20 10
200
Sample Output
Hint
To get the maximum number of tugriks in the first sample, you need to cook 2 buns with stuffing 1, 4 buns with stuffing 2 and a bun without any stuffing.
In the second sample Lavrenty should cook 4 buns without stuffings.
n克面粉,m种佐料,n克的面粉每c0克可以生成d0价值的产品,同时也可以与任意一种b克佐料混合生成d价值的产品,问这些东西最多制成多少价值的产品
dp[ i ][ j ][ k ],表示i种佐料使用j*c克混合k克面粉生成的价值,第i种佐料我们可以使用for循环控制,j*b克的i面粉跟k克的佐料是对应的,也就是说dp的值是由最后一维控制的,所以j*b也可以由循环表示,所以最后的dp是一维的
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[10000+10];
int main()
{
int n,m,c0,d0;
cin>>n>>m>>c0>>d0;
memset(dp,0,sizeof(dp));
for(int i=c0;i<=n;i++)
dp[i]=i/c0*d0;
int a,b,c,d;
for(int i=0;i<m;i++)
{
cin>>a>>b>>c>>d;
for(int j=1;j<=a/b;j++)//使用i最多生成a/b个合成品
{
for(int k=n;k>=c;k--)
dp[k]=max(dp[k-c]+d,dp[k]);
}
}
cout<<dp[n]<<endl;
return 0;
}
Codeforces--106C--Buns(背包)的更多相关文章
- Destroy the Colony CodeForces - 1111D (可逆背包,计数)
大意:给定字符串$s$, 保证长度为偶数, 给定q个询问, 每次询问给定两个位置$x$,$y$, 可以任意交换字符, 要求所有字符$s[x],s[y]$在同一半边, 剩余所有同种字符在同一半边的方案数 ...
- Codeforces 336C 0-1背包
题意:每个水果有两个值,一个美味度 a,一个卡路里 b,从中挑选一些,要求 sum(aj) / sum(bj) = k,使得 sum(a) 最大. 分析:没有那个条件就是一个01背包,可以转换,对公式 ...
- Codeforces 946 课程表背包DP 数位DFS构造
A B 给你A,B 两个数 1.a=0 OR b=0 break 2.a>=2b a=a-2b 3.b>=2a b=b-2a 如果只是单纯模拟肯定会超时 ...
- H - Fire CodeForces - 864E 01背包
https://codeforces.com/problemset/problem/864/E 这个题目要把这个按照物品毁灭时间进行排序,如果时间短就要排在前面,这个是因为要保证之后的物品的拯救不会影 ...
- codeforces 742D (分组背包)
D. Arpa's weak amphitheater and Mehrdad's valuable Hoses Just to remind, girls in Arpa's land are ...
- Knapsack CodeForces - 1132E (多重背包)
可以将大量同种物品合并为$lcm$来优化, 复杂度$O(nlcm^2)$, 好像可以用bitset优化到$O(nlcm^2/\omega)$, 但是没看太懂 const int L = 840, M ...
- CodeForces 106C 【DP】
题意: n g dough m种商品? 每种有ai stuffing, 拿bi stuffing + ci dough -> di tugriks rest c0 dough -> d0 ...
- Codeforces 913 二进制背包(柠檬水) 暴力贪心特殊背包(选题)
A B C 给你N(N<=30)种水瓶每种水瓶有无限个 每个的体积是2^(i-1)价格是cost[i] 要求你花最少的钱弄出L体积的水 先从前到后扫一遍cost[i+1]=min(cost[i+ ...
- CF dp 题(1500-2000难度)
前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的 ...
- 完全背包 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][ ...
随机推荐
- Android基础TOP4:Tost的使用
Activity: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xm ...
- html5——边框
精确控制 /*水平半径 垂直半径;*/ border-top-left-radius: 30px 40px; border-top-right-radius: 30px 40px; border-bo ...
- JS——scroll
scrollWidth:父div宽度小于子div宽度,父div scrollWidth宽度为子div的宽度,大于则为本身的宽度width+padding scrollHeight:父div高度小于子d ...
- NetBeans将java项目编译成jar包
1.找到file选项下的build.xml.
- CAD从二制流数据中加载图形(com接口)
主要用到函数说明: _DMxDrawX::ReadBinStream 从二制流数据中加载图形,详细说明如下: 参数 说明 VARIANT varBinArray 二制流数据,是个byte数组 BSTR ...
- Python-暑期实训day 1
python基础: 一 编程语言 什么是编程语言? 上面提及的能够被计算机所识别的表达方式即编程语言,语言是沟通的介质,而编程语言是程序员与计算机沟通的介质.在编程的世界里,计算机更像是人的奴隶,人类 ...
- uva 1586 Molar mass(Uva-1586)
这题做的相当的复杂...之前做的现在应该能简单一点了写的. 我的代码: #include <bits/stdc++.h> using namespace std; main() { int ...
- Django REST framework 渲染器、版本
渲染器.版本: # settings.py REST_FRAMEWORK = { "DEFAULT_RENDERER_CLASSES": [ "rest_framewor ...
- Jupyter Notebook 下安装 PHP 内核
我最近被强烈安利了 Jupyter Notebook 这个交互式笔记本.然后试用了它自带的 Python 内核后,这个应用整体给我的感觉很不错,就去搜索了下它所支持的其它内核 Jupyter Kern ...
- 使用PHP操作MongoDB数据库
1.连接MongoDB数据库(在已安装php-mongodb扩展的前提下) $config = "mongodb://{$user}:{$pass}@{$host}:{$port}" ...