面包师Lavrenty打算用馅料做几个面包,然后把它们卖掉。

Lavrenty有\(n\)克面团和\(m\)种不同的馅料。馅料种类的下标从\(1到m\),他知道他的第\(i\)种馅料剩下\(a_i\) 克,做一个第\(i\)种馅料的面包,恰恰需要\(b_i\)克的\(i\)种馅料和\(c_i\)克的面团,同时这种面包可以卖\(d_i\)块钱。

他也可以做没有馅的面包。每个这样的面包需要\(c_0\)克面团,可以卖\(d_0\)块Tugrik。所以Lavrenty可以做任何数量的包子,用不同的馅料或者不用馅料,除非用完了面团和馅料。Lavrenty会扔掉烘培面包后剩下的所有多余材料。

求出Lavrenty可以赚取的钱的最大数量。

输入格式

第一行4个整数n,m,\(c_0,d_0\) \(1<=n<=1000,1<=m<=10\)

接下来m行每行四个整数\(a_i,b_i,c_i,d_i\) \(1<=a_i,b_i,c_i,d_i<=100\)

输出格式

输出Lavrenty可以赚取的最大钱数

样例输入

10 2 2 1

7 3 2 100

12 3 1 10

样例输出

241

题解

很好的一道多重背包模板,然而却似乎没有很多人做?

这里放上两份代码,一份详细一份简单

#include<bits/stdc++.h>
#define maxm 50
#define maxn 1500
#define maxa 150
using namespace std;
inline char get(){
static char buf[3000],*p1=buf,*p2=buf;
return p1==p2 && (p2=(p1=buf)+fread(buf,1,3000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
register char c=get();register int f=1,_=0;
while(c>'9' || c<'0')f=(c=='-')?-1:1,c=get();
while(c<='9' && c>='0')_=(_<<3)+(_<<1)+(c^48),c=get();
return _*f;
}
int n,m;//n表示面团总数,m表示馅料种类
int a[maxn],d[maxn],b[maxn],c[maxn];
/*
a表示第i种馅料剩余数量
b表示第i种要的馅料数量
c表示第i种要的面团数量
d表示收益
*/
int dp[maxm][maxn];//第一维遍历面包种类,第二维遍历面团
int num;
int note[maxm][maxn];
int main(){
//freopen("1.txt","r",stdin);
n=read();m=read();
c[1]=read();d[1]=read();a[1]=0;b[1]=0;
//cout<<n<<m<<endl;
int out=-1;
for(register int i=2;i<=m+1;i++)a[i]=read(),b[i]=read(),c[i]=read(),d[i]=read();
for(register int i=1;i<=m+1;i++){//遍历面包种类
for(register int j=0;j<=n;j++){//遍历面团重量
for(register int k=0;k*b[i]<=a[i] && k*c[i]<=n;k++){
if(j>=c[i]*k){
dp[i][j]=max(dp[i-1][j-c[i]*k]+d[i]*k,dp[i][j]);
}
}
//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
out=max(out,dp[i][j]);
}
}
cout<<out<<endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[1500],d[1500],b[1500],c[1500];
int dp[15][1500];
int main(){
n=read();m=read();
cin>>c[1]>>d[1];a[1]=0;b[1]=0;
for(int i=2;i<=m+1;i++)a[i]=read(),b[i]=read(),c[i]=read(),d[i]=read();
for(int i=1;i<=m+1;i++){
for(int j=0;j<=n;j++){
for(int k=0;k*b[i]<=a[i] && k*c[i]<=n;k++){
if(j>=c[i]*k)dp[i][j]=max(dp[i-1][j-c[i]*k]+d[i]*k,dp[i][j]);
}
out=max(out,dp[i][j]);
}
}
cout<<out<<endl;
return 0;
}

[CF106C]Buns的更多相关文章

  1. Buns(dp+多重背包)

    C. Buns time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  2. 数学分析 + 容斥原理 - URAL 1907 Coffee and Buns

    Coffee and Buns Problem's Link: http://www.bnuoj.com/v3/contest_show.php?cid=6415#problem/H Mean: 给定 ...

  3. cf D. Physical Education and Buns

    http://codeforces.com/contest/394/problem/D 题意:给你n个数,然后通过操作使得这n个数变为一个等差数列,操作是可以经过小于等于k次加1或减去1,要使得k尽量 ...

  4. Codeforces 394D Physical Education and Buns 胡搞

    题目链接:点击打开链接 题意:给定n个数的序列(能够排序) 操作一次能够使得某个数++或--. 问最少操作几次使得序列变成一个等差序列 输出: 第一行输出最少操作的次数 第二行输出等差数列里的最小项 ...

  5. So many many foods here!

    水果类(fruits):西红柿 tomato 菠萝 pineapple 西瓜watermelon 香蕉banana 柚子 shaddock (pomelo) 橙子orange 苹果apple 柠檬le ...

  6. The 10 best sweet treats in Singapore

    Every time I walk out of Changi airport's air-conditioning into the humid outdoors, there's a sweet ...

  7. BZOJ1695 : [Usaco2007 Demo]Walk the Talk

    观察单词表可以发现: 对于长度为3的单词,前两个字母相同的单词不超过7个 对于长度为4的单词,前两个字母相同的单词不超过35个 于是首先$O(26*26*nm)$预处理出 s1[x][i][j]表示( ...

  8. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  9. R与数据分析旧笔记(十一)数据挖掘初步

    PART 1 PART 1 传统回归模型的困难 1.为什么一定是线性的?或某种非线性模型? 2.过分依赖于分析者的经验 3.对于非连续的离散数据难以处理 网格方法 <Science>上的文 ...

随机推荐

  1. EF Core 2.1 中的 Eager loading、Explicit loading和LazyLoading (转自MSDN)

    Entity Framework Core allows you to use the navigation properties in your model to load related enti ...

  2. Python 学习笔记(九)Python元组和字典(三)

    字典常用方法 copy() 返回一个字典的浅复制 示例:浅拷贝d.copy() 深拷贝引入import copy   copy.deepcopy() >>> help(dict.co ...

  3. DB数据源之SpringBoot+MyBatis踏坑过程(四)没有使用连接池的后果

    DB数据源之SpringBoot+MyBatis踏坑过程(四)没有使用连接池的后果 liuyuhang原创,未经允许禁止转载  系列目录连接 DB数据源之SpringBoot+Mybatis踏坑过程实 ...

  4. 可能是catalan数吧

    What's the number of distinct BSTs containing nodes {1, 2, 3 ,4}? 包含节点{1,2,3,4}的不同二叉搜索树有多少棵? int Num ...

  5. linux 学习第七天

    一.bash 使用(for循环.while循环) 1.1.批量添加用户 1.2.查看用户是否存在 A.cut -d : -f 1 /etc/passwd B.id dream  (id 用户名称) C ...

  6. RAID磁盘阵列的原理

    RAID概念 磁盘阵列(Redundant Arrays of Independent Disks,RAID),有“独立磁盘构成的具有冗余能力的阵列”之意.磁盘阵列是由很多价格较便宜的磁盘,以硬件(R ...

  7. QueryableHelper

    using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; us ...

  8. Apache Spark on K8s的安全性和性能优化

    前言 Apache Spark是目前最为流行的大数据计算框架,与Hadoop相比,它是替换MapReduce组件的不二选择,越来越多的企业正在从传统的MapReduce作业调度迁移到Spark上来,S ...

  9. 『Python基础-8』列表

    『Python基础-8』列表 1. 列表的基本概念 列表让你能够在一个地方存储成组的信息,其中可以只包含几个 元素,也可以包含数百万个元素. 列表由一系列按特定顺序排列的元素组成.你可以创建包含字母表 ...

  10. Python学习手册之元组拆包、三元运算符和 else 语句深入

    在上一篇文章中,我们介绍了 Python 之禅. Python 编程规范和函数参数,现在我们介绍 Python 的元组拆包.三元运算符和对 Python 的 else 语句深入讲解.查看上一篇文章请点 ...