hdu 2191 (多重背包)
来源:互联网 发布:c语言 rand 编辑:程序博客网 时间:2024/04/29 16:53
多重背包模板题。
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;const int maxn = 111;int n, m, V, f[maxn], cv[maxn], val[maxn], num[maxn];void ZeroOne(int cost, int value){ for(int j = V; j >= cost; j--) f[j] = max(f[j], f[j-cost] + value);}void Complete(int cost, int value){ for(int j = cost; j <= V; j++) f[j] = max(f[j], f[j-cost] + value);}void Multiple(int cost, int value, int amount){ int k = 1; if(cost * amount >= V) Complete(cost, value); else { while(amount >= k) { ZeroOne(cost * k, value * k); amount -= k; k *= 2; } ZeroOne(cost * amount, value * amount); }}void dp(){ for(int i=1; i<=n; i++) Multiple(cv[i], val[i], num[i]);}int main(){ int t; scanf("%d", &t); while(t--) { scanf("%d%d", &V, &n); for(int i=1; i<=n; i++) scanf("%d%d%d", &cv[i], &val[i], &num[i]); memset(f, 0, sizeof(f)); dp(); printf("%d\n", f[V]); }}
- hdu 2191 多重背包
- HDU-2191 多重背包
- hdu 2191 多重背包
- hdu 2191 (多重背包)
- hdu 2191(多重背包)
- hdu 2191 多重背包
- HDU 2191 多重背包
- HDU 2191 多重背包
- HDU 2191 多重背包
- hdu 2191 多重背包
- hdu 2191 多重背包
- hdu 2191 多重背包
- HDU 2191 (多重背包)
- hdu 2191(多重背包)
- HDU 2191(多重背包)
- 多重背包 HDU 2191
- hdu 2191 多重背包
- HDU 2191 多重背包
- AndroidManifest.xml文件综合详解
- C/C++ 时间
- 同志们,你们面试的第一句话和最后一句话是什么?
- Linux驱动之platform初识
- JNI 调试打印信息
- hdu 2191 (多重背包)
- updated
- jQuery ajax调用本页面后台方法Demo
- C#调用Arcgis API切割遥感影像数据
- Mysql初始化root密码和允许远程访问
- 如何强制用户通过HTTPS SSL访问网站
- 编译jrtp和jthread
- 通过javaScript异步提交到后台的空值问题
- Android调用相册、拍照实现缩放、切割图片