题目描述:

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.
Examples
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
Note
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,x,y;
四个数,分别表示n克面粉, m种有馅料的面包。 x,y表示没有馅料的面包所需要的面粉和售价。
接下来m行,每行给出每种有馅料的面包的基本情况。
a,b,c,d。
分别表示,馅料有a克,做一个这样的馅料面包要b克馅料。c克面粉。售价d元。

分析:
这个题有馅料的面包能做的个数是有限制的,被面粉数量和馅料数量限制。
没有馅料的面包能做的个数,仅被面粉数量限制。
我们可以先不考虑面粉数量限制。
那么这个题的基本思路就将有馅料的面包当作多重背包。
没有馅料的面包当作完全背包。
看数据范围都比较小。 那么可以不用优化。

#include"stdio.h"
#include"string.h"
#include"functional"
#include"iostream"
#include"algorithm"using namespace std;
typedef long long ll;
#define scanll(a,b) scanf("%I64d%I64d",&a,&b);
#define scanl(a) scanf("%I64d",&a);
#define scanff(a,b) scanf("%lf%lf",&a,&b);
#define scan1f(a) scanf("%lf",&a);
#define prinll(a,b) printf("%I64d %I64d",a,b);
#define prinl(a) printf("%I64d",a);
#define printff(a,b) printf("%lf %lf",a,b);
#define printlf(a) printf("%lf",a);
#define OK printf("\n");
#define MAXSIXE 100100
ll dp[MAXSIXE];
struct Good
{ll p;ll v;ll cnt;
}goods[11];
int main()
{ll n,m,x,y;scanll(n,m);scanll(x,y);for(ll i = 1; i <= m; i ++){ll a,b,c,d;scanll(a,b); scanll(c,d);ll cnt = a / b <  n / c ? a / b : n / c;goods[i] = {d, c ,cnt};//  printf("%lld %lld %lld \n",goods[i].p,goods[i].v,goods[i].cnt);}//完全背包。没有馅料的面包for(ll j = x; j <= n; j ++) dp[j] = dp[j - x] + y;//多重背包for(ll i = 1; i <= m; i ++){for(ll j = n; j >= goods[i].v; j --){for(ll k = 0; k <= goods[i].cnt; k ++){if(j >= k * goods[i].v)dp[j] = max(dp[j],dp[j - k * goods[i].v] + k * goods[i].p);}}}printf("%lld\n",dp[n]);
}

O - Buns(混合背包)相关推荐

  1. Codevs 3269 混合背包

    3269 混合背包 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 背包体积为V ,给出N个物品,每个物品占用体积为Vi,价值 ...

  2. 九十一、动态规划系列 背包问题之混合背包

    @Author:Runsen @Date:2020/09/27 背包系列,是动态规划里一类典型的问题,主要有:01背包,完全背包,多重背包,混合背包,二维费用背包,分组背包,有依赖背包和泛化物品等.也 ...

  3. P1833 樱花——混合背包 二进制优化成01背包

    P1833樱花 题目大意:有n颗樱花树,你的总时间为T,现在n课树,每次观看要花费w时间,能获取v点价值,最多能参观s次,如果s等于0,则可以观看无限次,问你在T时间内 获得的最大价值是多少. 思路: ...

  4. CODEVS 3269 混合背包

    一道裸的混合背包题目.可是忘记了去重一直TLE,就是假设体积<=全然背包的01.和多重背包都要被全然背包代替,由于他的数量没限制所以用起来更方便. 题目连接:http://codevs.cn/p ...

  5. Codevs 3269 混合背包(二进制优化)

    3269 混合背包 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 传送门 题目描述 Description 背包体积为V ,给出N个物品,每个物品占用体积为V ...

  6. hdu 3535 AreYouBusy 经典混合背包

    借此机会,整理一下背包中的某几类问题: 物品分组,每组至少选一个: 这个时候 写法1:看别人博客,这样写省去了某些麻烦问题 达不到的dp值为-INF dp[i][j]=max(dp[i][j],max ...

  7. 动态规划dp(带模板题の超易懂版):01背包,完全背包,分组背包,多重背包,混合背包

    动态规划dp(带模板题の超易懂版):01背包,完全背包,分组背包,多重背包 01背包 && 完全背包 && 分组背包 の 视频教程:https://www.bilibi ...

  8. 一本通 1270:【例9.14】混合背包(混合背包模板题)

    [题目描述] 一个旅行者有一个最多能装V公斤的背包,现在有n件物品,它们的重量分别是W1,W2,-,Wn,它们的价值分别为C1,C2,-,Cn.有的物品只可以取一次(01背包),有的物品可以取无限次( ...

  9. 信息学奥赛一本通 1270:【例9.14】混合背包

    [题目链接] ybt 1270:[例9.14]混合背包 [题目考点] 1. 动态规划:混合背包 [解题思路] 混合背包问题,解法如下: 解法1:根据第i物品存在的个数进行分类讨论. 如果只有1个第i物 ...

  10. 一本通 1270:【例9.14】混合背包

    混合背包 混合背包模板题. #include <iostream> #include <cstdio> using namespace std; //Mystery_Sky / ...

最新文章

  1. 几个有趣的名词--语法糖、语法盐等
  2. [导入]看图说话,编写VS2005插件,增强VS2005 IDE
  3. 读取excel文件内容代码
  4. MySQL MHA 搭建测试
  5. MongoDB Hot Backup 测试及痛点
  6. hasOwnProperty()方法与in操作符
  7. 贪吃蛇c语言代码 链表,链表贪吃蛇 附代码
  8. 电子发票中数字签名的提取解析教程
  9. VScode+latex+Sumatra PDF环境配置(步步到位)
  10. owncloud server replied : locked 故障处理
  11. 找到数据库中最大数据量的表
  12. 二十二、商城 - 商品录入-FastDFS(10)
  13. 一次手动查杀永恒之蓝病毒木马文件
  14. neo4j的使用(以红楼梦人物关系为例)
  15. 快速破解ViEmu软件
  16. 小可爱 java实训课程06 jdbc
  17. 计算机视觉学习日记2
  18. 信贷管理系统开发,学习[转]
  19. Vivado[DRC 23-20]
  20. 麦芽糖-聚乙二醇-甲氨蝶呤 MTX-PEG-maltose

热门文章

  1. MaixII-Dock(v831)学习笔记——PWM
  2. Rust包管理 Crate
  3. PHP中冒号加引号,冒号的五种用法 冒号引号的三种用法
  4. 移动硬盘linux读取失败,无法读取移动硬盘|无法识别的6种修复方法插图
  5. Linux下简单编译so库,调用另一个so库的方法
  6. PDA库存盘点,有效提高电子制造企业库存盘点效率
  7. 无穷积分 ∫e^(-x^2)dx 的几种巧妙解法
  8. 计算机应用对交通,计算机应用基础 交通学习文学.pdf
  9. 【eNSP 华为模拟器】三层交换技术及操作步骤【图文】
  10. 求丑数(判断一个整数是否是丑数)