Codeforces--106C--Buns(背包)
Time Limit: 2000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
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
10 2 2 1
7 3 2 100
12 3 1 10
241
100 1 25 50
15 5 20 10
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(背包)的更多相关文章
- Destroy the Colony CodeForces - 1111D (可逆背包,计数)
大意:给定字符串$s$, 保证长度为偶数, 给定q个询问, 每次询问给定两个位置$x$,$y$, 可以任意交换字符, 要求所有字符$s[x],s[y]$在同一半边, 剩余所有同种字符在同一半边的方案数 ...
- Codeforces 336C 0-1背包
题意:每个水果有两个值,一个美味度 a,一个卡路里 b,从中挑选一些,要求 sum(aj) / sum(bj) = k,使得 sum(a) 最大. 分析:没有那个条件就是一个01背包,可以转换,对公式 ...
- 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 如果只是单纯模拟肯定会超时 ...
- H - Fire CodeForces - 864E 01背包
https://codeforces.com/problemset/problem/864/E 这个题目要把这个按照物品毁灭时间进行排序,如果时间短就要排在前面,这个是因为要保证之后的物品的拯救不会影 ...
- codeforces 742D (分组背包)
D. Arpa's weak amphitheater and Mehrdad's valuable Hoses Just to remind, girls in Arpa's land are ...
- Knapsack CodeForces - 1132E (多重背包)
可以将大量同种物品合并为$lcm$来优化, 复杂度$O(nlcm^2)$, 好像可以用bitset优化到$O(nlcm^2/\omega)$, 但是没看太懂 const int L = 840, M ...
- CodeForces 106C 【DP】
题意: n g dough m种商品? 每种有ai stuffing, 拿bi stuffing + ci dough -> di tugriks rest c0 dough -> d0 ...
- Codeforces 913 二进制背包(柠檬水) 暴力贪心特殊背包(选题)
A B C 给你N(N<=30)种水瓶每种水瓶有无限个 每个的体积是2^(i-1)价格是cost[i] 要求你花最少的钱弄出L体积的水 先从前到后扫一遍cost[i+1]=min(cost[i+ ...
- CF dp 题(1500-2000难度)
前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的 ...
- 完全背包 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][ ...
随机推荐
- html5——多媒体(一)
<audio> 1.autoplay 自动播放 2.controls 是否显不默认播放控件 3.loop 循环播放 4.preload 预加载 同时设置autoplay时些属性失效 5.由 ...
- JS——input标签注册事件
注意:淘宝的lable是用定位制作的,事件是oninput事件 <!DOCTYPE html> <html> <head lang="en"> ...
- [Windows Server 2012] 服务器安全加固
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:服务器安全加固 ...
- 扩增子图表解读1箱线图:Alpha多样性
箱线图 箱形图(Box-plot)又称为盒须图.盒式图或箱线图,是一种用作显示一组数据分散情况资料的统计图.因形状如箱子而得名.在宏基因组领域,常用于展示样品组中各样品Alpha多样性的分布 第一种情 ...
- spring IOC bean间关系
1.0 继承关系 实体 package com.java.test5; import java.util.*; /** * @author nidegui * @create 2019-06-22 1 ...
- 手撸HashMap实现
前言 HashMap是Java中常用的集合,而且HashMap的一些思想,对于我们平时解决业务上的一些问题,在思路上有帮助,基于此,本篇博客将分析HashMap底层设计思想,并手写一个迷你版的Hash ...
- python 列出出当前目录及所有子目录下的文件
[root@web1 test]# cat walk.py #!/usr/bin/python # -*- coding: UTF-8 -*- import os for root, dirs, fi ...
- LVM和RAID
RAID: Redundant Arrays of Inexpensive Disks Independent Berkeley: A case for Redundent Arrays of Ine ...
- 8.mysql执行语句的顺序
mysql执行语句的顺序 一.group by + where group by 字句和where条件语句结合在一起使用,where在前,group by 在后.即先对select xx fr ...
- PAT 1107 Social Clusters
When register on a social network, you are always asked to specify your hobbies in order to find som ...