Codeforces 106C 多重背包
来源:互联网 发布:手写笔记软件 编辑:程序博客网 时间:2024/06/07 04:52
题目链接:点击打开链接
题意:
有 n 种原料,m 种产品;
其中每种产品有 ai 个高级原料;
生产某种产品需要 bi 个高级原料,ci 个原料;
每件产品有 di 的价值;
其中有种产品是只用原料做成的;
该产品需要 c0 个原料,有 d0 的价值;
求用这些原料能得到的最大价值;
理解:
多重背包模板题;
将所有的物品转化成最多可用 num[i] 个;
每个有 v[i] 的价值,w[i] 的花费;
然后套模板;
代码如下:
#include <cstdio>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <vector>#include <string>#include <map>#include <set>#include <queue>#include <stack>using namespace std;typedef long long LL;typedef pair<int, int> PII;const int MIN_INF = 1e-7;const int MAX_INF = (1e9) + 7;#define X first#define Y secondint dp[2222]; //dp[i] 表示int main() { int n, m, c0, d0; cin >> n >> m >> c0 >> d0; vector<int> v(m + 1), w(m + 1), num(m + 1); for (int i = 0; i < m; ++i) { int a, b, c, d; cin >> a >> b >> c >> d; v[i] = d; w[i] = c; num[i] = min(a / b, n / c); } v[m] = d0; w[m] = c0; num[m] = n / c0; for (int i = 0; i < m + 1; ++i) { int x = num[i]; for (int k = 1; x > 0; k <<= 1) { int mul = min(k, x); for (int j = n; j >= w[i] * mul; --j) { dp[j] = max(dp[j], dp[j - w[i] * mul] + v[i] * mul); } x -= mul; } } cout << dp[n] << endl; return 0;}
0 0
- Codeforces 106C 多重背包
- Codeforces 106 C Buns【多重背包】
- codeforces 106C. Buns【多重背包】
- Codeforces 106 C Buns【多重背包】
- CodeForces 106C Buns 多重背包
- CodeForces 106C Buns (多重背包)
- Codeforce 106C(多重背包)
- codeforces 148E Porcelain 多重背包
- Codeforces 148E. Porcelain【多重背包】
- Codeforces 577B Modulo Sum 【多重背包】
- Codeforces 106C Buns 【0-1背包】
- Codeforces--106C--Buns(背包)
- Codeforces 148E Porcelain (预处理+多重背包)
- codeforces 755F PolandBall and Gifts(多重背包)
- 多重背包
- 多重背包
- 多重背包
- 多重背包
- Struts用Iterator读取List对象中的每个属性
- hdu 1850 Being a Good Boy in Spring Festival(尼姆博弈)
- [DP]Desigin Pattern Overview
- PHP中对象是按值传递还是按引用传递?
- hostapd wpa_supplicant madwifi详细分析(十三)——EAPOL(802.1X-2004/IEEE Std 802.1X-2010)
- Codeforces 106C 多重背包
- bzoj2456
- JAVA编码习惯
- 获取客户端IP地址
- Session小记
- 【1】【二分搜索】CodeForces 492D Vanya and Computer Game
- (NYoj 311) 完全背包 --完全背包模板题
- HDU 1850 Being a Good Boy in Spring Festival (Nim博弈求第一步选择数)
- golang中的RPC调用服务器方法