CSU1086-超市购物-分组背包
来源:互联网 发布:二六三网络通信 编辑:程序博客网 时间:2024/06/03 00:32
J: 超市购物
Description
上次去超市扫荡回来的东西用完了,Staginner又得跑超市一趟,出发前他列了一张购物清单,打算去买K种不同的商品,每种买一件。到了超市,Staginner发现每种商品有N个品牌,每个品牌此商品的价格为Vi,对Staginner的作用值为Wi,他会从这N个品牌里面挑一个品牌买。这时,Staginner突然想起出门时只带了M元钱,又懒得去取钱了,所以不一定能买完K种商品,只好尽可能地让买的东西对自己的总作用值ans最大。
Input
多组样例。
第一行两个整数K,M代表Staginner想买的不同种类商品的数目和他带的钱 (0 < K <= 30, 0 < M <= 2000)
以下输入分为K个部分,代表K种商品。
每个部分第一行为一个数字N,代表第k种商品的N个品牌,N不大于10。之后跟着N行,每行两个数字,代表物品的价格Vi和作用值Wi。其中 0 < Vi < M。
Output
输出Case #: 最大总作用值,每两个样例之间有一个空行。
Sample Input
3 100350 60020 70030 800 230 50040 600 160 2002 5002200 1000260 12001280 300
Sample Output
Case 1: 1400Case 2: 1300
裸的分组背包问题,记得注意输出格式
背包问题建议看看《背包九讲》,写自己模板的话我推荐写一下HihoCoder的奖券兑换,裸的多重背包题
#include <bits/stdc++.h>#define N 10100#define INF 0x3f3f3f3f#define LL long long#define mem(a,n) memset(a,n,sizeof(a))#define fread freopen("in.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;int cost[33][11],amount[33],val[33][11],dp[2222];int main(){ ios::sync_with_stdio(false); int kase=0,k,mon; while(cin>>k>>mon){ if(kase){ cout<<endl; } mem(dp,0); for(int i=0;i<k;++i){ cin>>amount[i]; for(int j=0;j<amount[i];++j){ cin>>cost[i][j]>>val[i][j]; } } for(int i=0;i<k;++i){ for(int j=mon;j>=0;--j){ for(int l=0;l<amount[i];++l){ if(j>=cost[i][l]){ dp[j]=max(dp[j],dp[j-cost[i][l]]+val[i][l]); } } } } cout<<"Case "<<++kase<<": "<<dp[mon]<<endl; } return 0;}/********************************************************************** Problem: 1086 User: CSUzick Language: C++ Result: AC Time:48 ms Memory:1700 kb**********************************************************************/
阅读全文
0 0
- CSU1086-超市购物-分组背包
- csu1086(超市购物)(分组背包)
- CSU 1086 超市购物 分组背包问题
- 超市购物
- 超市购物预测
- 超市购物管理系统
- 超市购物系统
- CSU 1086 超市购物
- 超市购物简例
- csu----超市购物
- 超市购物小票案例
- 分组背包
- 分组 背包
- 分组背包
- 分组背包
- 分组背包
- 分组背包
- 分组背包
- CSU1023-修路-二分
- Seafile 个人网盘配置安装
- CSU1065-Scientific Conference-贪心
- 6174问题
- 使用Ettercap filter进行流量监听和数据篡改
- CSU1086-超市购物-分组背包
- CSU1090-Number Transformation-BFS
- VMware虚拟机磁盘操作占用过高问题
- Python语言里的method auto bind与JavaScript ES5显式function.bind语法
- CSU1093-Caps Lock-模拟
- 使用python实现用微信远程控制电脑
- delphi xe 之路(14)使用FireMonkeyStyle
- [翻译]Django1.11 Writing your first Django app, part 1
- CSU1101-报数游戏-模拟、枚举