Buns

Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit
Status

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

Input
10 2 2 1
7 3 2 100
12 3 1 10
Output
241
Input
100 1 25 50
15 5 20 10
Output
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(背包)的更多相关文章

  1. Destroy the Colony CodeForces - 1111D (可逆背包,计数)

    大意:给定字符串$s$, 保证长度为偶数, 给定q个询问, 每次询问给定两个位置$x$,$y$, 可以任意交换字符, 要求所有字符$s[x],s[y]$在同一半边, 剩余所有同种字符在同一半边的方案数 ...

  2. Codeforces 336C 0-1背包

    题意:每个水果有两个值,一个美味度 a,一个卡路里 b,从中挑选一些,要求 sum(aj) / sum(bj) = k,使得 sum(a) 最大. 分析:没有那个条件就是一个01背包,可以转换,对公式 ...

  3. 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 如果只是单纯模拟肯定会超时 ...

  4. H - Fire CodeForces - 864E 01背包

    https://codeforces.com/problemset/problem/864/E 这个题目要把这个按照物品毁灭时间进行排序,如果时间短就要排在前面,这个是因为要保证之后的物品的拯救不会影 ...

  5. codeforces 742D (分组背包)

    D. Arpa's weak amphitheater and Mehrdad's valuable Hoses   Just to remind, girls in Arpa's land are ...

  6. Knapsack CodeForces - 1132E (多重背包)

    可以将大量同种物品合并为$lcm$来优化, 复杂度$O(nlcm^2)$, 好像可以用bitset优化到$O(nlcm^2/\omega)$, 但是没看太懂 const int L = 840, M ...

  7. CodeForces 106C 【DP】

    题意: n g dough  m种商品? 每种有ai stuffing, 拿bi stuffing + ci dough -> di tugriks rest c0 dough -> d0 ...

  8. Codeforces 913 二进制背包(柠檬水) 暴力贪心特殊背包(选题)

    A B C 给你N(N<=30)种水瓶每种水瓶有无限个 每个的体积是2^(i-1)价格是cost[i] 要求你花最少的钱弄出L体积的水 先从前到后扫一遍cost[i+1]=min(cost[i+ ...

  9. CF dp 题(1500-2000难度)

    前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的 ...

  10. 完全背包 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][ ...

随机推荐

  1. Mediacodec编码后的h264视频出现马赛克问题

    问题:在视频采集后,通过Mediacodec编码生成h264视频文件,播放时出现马赛克较多,无论调整帧率.码率.还是分辨率都不能解决问题 出现问题的原因:编码时传入的时间戳不对.时间戳是视频播放的标准 ...

  2. JS——绑定自定义属性

    1.绑定自定义属性: (1)元素节点.属性或元素节点[属性]绑定的属性不会出现在标签中,setAttribute可以出现在标签中. (2)setAttribute获取不到元素节点.属性形式绑定的属性值 ...

  3. 【sqli-labs】 less49 GET -Error based -String -Blind -Order By Clause(GET型基于盲注的字符型Order By从句注入)

    都是order by的注入,作者连图片都懒得改了... 注意和整型的区别,前引号用提交的引号闭合,后引号用#注释 http://192.168.136.128/sqli-labs-master/Les ...

  4. Ubuntu 常用解压与压缩命令

    参考 https://blog.csdn.net/songbinxu/article/details/80435665 示例: 把/home/wangju/gitlab/automationTest目 ...

  5. ubuntu.16.04 安装.net core记录

    jack@ubuntu:~$ sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotne ...

  6. 微智魔盒APP开发程序解析

    微智魔盒系统开发找崔经理l88Z.6ZZ685l.微智魔盒app开发.微智魔盒商城开发.微智魔盒软件开发,微智魔盒模式开发,微智魔盒源码开发.微智魔盒开发. @Override publicvoidr ...

  7. DNS详细解析过程【转】

    转自:http://blog.csdn.net/crazw/article/details/8986504 先说一下DNS的几个基本概念: 一. 根域 就是所谓的“.”,其实我们的网址www.baid ...

  8. 通过git向github提交项目

    按顺序学习 https://www.cnblogs.com/forget406/p/6045499.html#top https://blog.csdn.net/xiaoputao0903/artic ...

  9. String s="a"+"b"+"c"+"d";创建了几个对象?

    对于如下代码: package reviewTest; /** * @ClassName: StringTest * @Description: 测试String的字符串相加优化 * @author ...

  10. 使用Python的Flask框架,结合Highchart,动态渲染图表(Ajax 请求数据接口)

    参考链接:https://www.highcharts.com.cn/docs/ajax 参考链接中的示例代码是使用php写的,这里改用python写. 需要注意的地方: 1.接口返回的数据格式,这个 ...