codeforces 106C. Buns【多重背包】
来源:互联网 发布:linux 安装中文字符集 编辑:程序博客网 时间:2024/05/18 14:46
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.
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 contains4 integers. The i-th line contains numbers ai, bi, ci and di (1 ≤ ai, bi, ci, di ≤ 100).
Print the only number — the maximum number of tugriks Lavrenty can earn.
10 2 2 17 3 2 10012 3 1 10
241
100 1 25 5015 5 20 10
200
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种馅料,然后还可以做不带馅儿的包子,首先给出所需的面粉量和能够出售的价格,之后给出每种馅料的量以及该种包子所需的面粉量和馅料量以及和出售的价格,然后问最多能得到多少钱。多重背包,只会找模板。。。
#include <iostream>#include<cstdio>#include<cstring>#include<vector>#include<queue>#include<algorithm>#define maxn 1010using namespace std;int c[maxn],d[maxn];int num[maxn],f[maxn];int main(){ int sd,m,a,b,c0,d0; while(~scanf("%d%d%d%d",&sd,&m,&c0,&d0)) { for(int i=c0;i<=sd;++i) f[i]=i/c0*d0; for(int i=0;i<m;++i) { scanf("%d%d%d%d",&a,&b,&c[i],&d[i]); num[i]=a/b; } for(int i=0;i<m;++i) { for(int j=0;j<num[i];++j) { for(int k=sd;k>=c[i];k--) { f[k]=max(f[k],f[k-c[i]]+d[i]); } } } printf("%d\n",f[sd]); } return 0;}
- Codeforces 106 C Buns【多重背包】
- codeforces 106C. Buns【多重背包】
- Codeforces 106 C Buns【多重背包】
- CodeForces 106C Buns 多重背包
- CodeForces 106C Buns (多重背包)
- Codeforces 106C Buns 【0-1背包】
- Codeforces--106C--Buns(背包)
- codeforces 106C Buns
- Codeforces 106C Buns
- Codeforces 106C 多重背包
- CodeForces 106C Buns (01beoba)
- CF 106C Buns
- Buns CodeForces
- CF 106C Buns 再解
- Codeforce 106C(多重背包)
- codeforces 148E Porcelain 多重背包
- Codeforces 148E. Porcelain【多重背包】
- Codeforces 577B Modulo Sum 【多重背包】
- NYOJ5056_黑色帽子(水题)
- D2D画箭头的例子
- Android Fragment 真正的完全解析(上)
- 第2周.项目3:小试循环
- 第二周项目3 小试循环
- codeforces 106C. Buns【多重背包】
- 银行业务-贷款
- POJ 2096 概率dp
- 算法训练 暗恋
- Java IO——File类
- Handler用法
- ACM2014
- php五大运行模式CGI,FAST-CGI,CLI,ISAPI,APACHE模式浅谈
- HDUACM2017