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][ ...
随机推荐
- tomcat报错org.springframework.web.context.ContextLoaderListener找不到
tomcat报错org.springframework.web.context.ContextLoaderListener找不到. 最后解决办法:将jar包copy到web-inf下面的lib中. 你 ...
- cms判断写法
cms比较容易写出循环的网页内容,对于有些循环的网页内容有不同css设定,这样在写cms时需要对循环做出条件判断:{if 判断条件}输出内容{else}输出内容{/if}.通过判断可以实现图片轮播效果 ...
- JS——高级各行换色
1.获取tbody下的子元素 2.注册鼠标覆盖事件时存储当时的背景颜色,注册鼠标离开事件时把存储的颜色赋值注册事件对象 <!DOCTYPE html> <html> <h ...
- pengyue-form 模块 dropdown 关系联动
<script> window.onload=function() { var school= document.getElementById("dnn_ctr5973_View ...
- DOM对象之window
window的属性 top:返回当前窗口的最顶层的先辈窗口 document:返回HTML文档对象 location:当前窗口的地址 self:返回对自身窗口的引用 parent:返回父窗口 如何引用 ...
- log4j最全教程
(转自http://www.codeceo.com/article/log4j-usage.html) 日志是应用软件中不可缺少的部分,Apache的开源项目log4j是一个功能强大的日志组件,提供方 ...
- html table内容不随标题滚动
<html><head></head><body> <div> <div id="demo" style=&quo ...
- [SQL Server] 常用sql脚本
1.添加表 GO IF NOT EXISTS(SELECT * FROM sys.tables WHERE name='table_name') BEGIN CREATE TABLE [dbo].[t ...
- String s = new String("xyz");创建了几个对象?
两个或一个都有可能 . ”xyz”对应一个对象,这个对象放在字符串常量池,常量”xyz”不管出现多少遍,都是常量池中的那一个. new String每写一遍,就创建一个新的对象,它使用常量”xyz”对 ...
- 爬虫文件存储-1:mysql
1.连接并创建数据库 import pymysql db = pymysql.connect(host='localhost', user='root', password='root', port= ...