题目: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

大意:
n:一共有ng面团
m:有m种馅
a[]:每种馅还剩多少
b[],c[]:每做一种馅饼需要bg馅和cg面团
d[]:每一种馅饼可以买多少钱
dp[]:最多可以买多少钱
c[0],d[0]:做馒头需要的面团c[0]g 能买d[0]的钱

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=20,INF=0x3f3f3f3f;
int a[N],b[N],c[N],d[N];
int dp[1007]={0};
int main()
{int n,m;scanf("%d%d%d%d",&n,&m,&c[0],&d[0]);for(int i=1;i<=m;i++)scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);for(int i=c[0];i<=n;i++)//所有的面团用来做馒头能赚多少dp[i]=i/c[0]*d[0];for(int i=1;i<=m;i++)for(int k=0;k<a[i]/b[i];k++)//有a[i]/b[i]份的馅j就可以循环k次把所有的馅用进去(知道没有馅为止)for(int j=n;j>=c[i];j--)dp[j]=max(dp[j],dp[j-c[i]]+d[i]);printf("%d\n",dp[n]);
}

CF Buns (01背包问题)相关推荐

  1. ACM1881 01背包问题应用

    01背包问题动态规划应用 acm1881毕业bg 将必须离开的时间限制看作背包容量,先将他们由小到大排序,然后在排完序的数组中对每个实例都从它的时间限制开始(背包容量)到它的延长时间进行遍历: 1 # ...

  2. c语言-01背包问题

    01背包问题 问题:有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使价值总和最大. 分析: 这是最基础的背包问题,特点是:每种物品仅有一件,可以选 ...

  3. 三十四、动态规划解决01背包问题

    一.动态规划算法介绍 动态规划算法的核心思想是:将大问题划分为小问题进行解决,从而一步一步获取最优解的处理算法. 动态规划算法与分治算法类似,其基本思想是将待求解的问题分解成若干个子问题,先求子问题, ...

  4. python 回溯法 子集树模板 系列 —— 3、0-1背包问题

    问题 给定N个物品和一个背包.物品i的重量是Wi,其价值位Vi ,背包的容量为C.问应该如何选择装入背包的物品,使得放入背包的物品的总价值为最大? 分析 显然,放入背包的物品,是N个物品的所有子集的其 ...

  5. poj3624 Charm Bracelet DP 01背包问题

    题目链接:http://poj.org/problem?id=3624 01背包问题,接触DP的第一题. 1 ///2014.4.10 2 ///poj3624 3 4 #include <io ...

  6. 【基础算法复习】01背包问题(一)

    一.绪论 01背包问题是一个经典的动态规划问题,问题描述为"有n个物品,其价值分别为v[n],要求将其装在承重为m的背包,每个物品只能装一次的情况下,在不超过承重的范围下价值最大" ...

  7. C++~回溯+贪心法解决01背包问题

    C++~回溯+贪心法解决01背包问题 参考文章: (1)C++~回溯+贪心法解决01背包问题 (2)https://www.cnblogs.com/rimochiko/p/8168638.html 备 ...

  8. 0-1背包问题 动态规划java_C#使用动态规划解决0-1背包问题实例分析

    // 利用动态规划解决0-1背包问题 using System; using System.Collections.Generic; using System.Linq; using System.T ...

  9. 算法导论——动态规划:0-1背包问题(完全解)

    2019独角兽企业重金招聘Python工程师标准>>> package org.loda.dynamic;import org.junit.Test;/*** * @ClassNam ...

  10. 动态规划之 0-1背包问题及改进

    有N件物品和一个容量为V的背包.第i件物品的重量是w[i],价值是v[i].求解将哪些物品装入背包可使这些物品的重量总和不超过背包容量,且价值总和最大.在选择装入背包的物品时,对于每种物品i,只能选择 ...

最新文章

  1. 无法访问D盘,执行页内操作时的错误
  2. 蚂蚁开源增强版 SpringBoot,都有哪些骚能力?
  3. Spring 在 xml配置文件 或 annotation 注解中 运用Spring EL表达式
  4. Win10安装玩Ubuntu19.04后,bios和grub页面都没有Windows启动项,无法进入Windows
  5. staf工作笔记-使用stax并行处理获取其他主机操作系统信息
  6. 解决selenium连接driver报错Message: Can not connect to the Service chromedrive
  7. mybatis # $区别
  8. 关于母板页中runnat=server 窗体标记的问题
  9. java+widthstep,i*step+j*channels+k 以及widthStep大小计算及原理
  10. 连接跟踪子系统之helper
  11. Codeforces 1179C Serge and Dining Room 线段树
  12. 微带线电容设计与仿真
  13. 基于微信小程序的二手闲置跳蚤市场交易平台 uni-app
  14. 基于文心大模型的剧本杀海报生成器(武侠篇)
  15. linux jboss的安装路径,LINUX下JBOSS的安装及配置
  16. 三国论(21-25章)
  17. 三极管的三个工作状态和作用
  18. Netty应用实战:客户端重连
  19. Mldonkey端口映射获取High id
  20. java的Intersect用法_SQL INTERSECT的用法

热门文章

  1. git stash drop 误删恢复
  2. 《关键对话》要点整理
  3. J - 山峰和山谷 Ridges and Valleys
  4. 写在微信小程序一周年
  5. 播布客视频PIT专用播放器MBOO2015
  6. 【萌新笔记】简单记录“智能管家”的设计过程
  7. D - Inna and Alarm Clock
  8. 计算机无法装补丁,Win7系统无法安装补丁提示缺少Service Pack系统组件的原因及解决方法...
  9. nodejs压缩成7z_[Node] 传智NodeJS前端与移动开发顶级全套视频教程完整版
  10. 导函数连续、可导、可微、连续、有界、可积的关系,史上最全!一张图搞定!