POJ 1170 Shopping Offers非状态压缩做法
Shopping Offers
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 5659 Accepted: 2361
Description
In a shop each kind of product has a price. For example, the price of a flower is 2 ICU (Informatics Currency Units) and the price of a vase is 5 ICU. In order to attract more customers, the shop introduces some special offers.
A special offer consists of one or more product items for a reduced price. Examples: three flowers for 5 ICU instead of 6, or two vases together with one flower for 10 ICU instead of 12.
Write a program that calculates the price a customer has to pay for certain items, making optimal use of the special offers. That is, the price should be as low as possible. You are not allowed to add items, even if that would lower the price.
For the prices and offers given above, the (lowest) price for three flowers and two vases is 14 ICU: two vases and one flower for the reduced price of 10 ICU and two flowers for the regular price of 4 ICU.
Input
Your program is to read from standard input. The first line contains the number b of different kinds of products in the basket (0 <= b <= 5). Each of the next b lines contains three values c, k, and p. The value c is the (unique) product code (1 <= c <= 999). The value k indicates how many items of this product are in the basket (1 <= k <= 5). The value p is the regular price per item (1 <= p <= 999). Notice that all together at most 5*5=25 items can be in the basket. The b+2nd line contains the number s of special offers (0 <= s <= 99). Each of the next s lines describes one offer by giving its structure and its reduced price. The first number n on such a line is the number of different kinds of products that are part of the offer (1 <= n <= 5). The next n pairs of numbers (c,k) indicate that k items (1 <= k <= 5) with product code c (1 <= c <= 999) are involved in the offer. The last number p on the line stands for the reduced price (1 <= p <= 9999). The reduced price of an offer is less than the sum of the regular prices.
Output
Your program is to write to standard output. Output one line with the lowest possible price to be paid.
Sample Input
2
7 3 2
8 2 5
2
1 7 3 5
2 7 1 8 2 10
Sample Output
14
Source
IOI 1995
这是个五维背包问题,背包容量为篮子中各类物品的数量,每种打折情况当成一种商品,代价是包含的物品种类及数量,价值是花费。一看这个题就明了了,那么恭喜你,入坑了,如果只是买打折商品,能不能花费最少先放一边,能不能买完就不现实。所以还要把原价当成一种商品,对于商品的种类,他给的数不连续,写起来麻烦,直接STL离散化。差不多这个题就做出来了。
下面是丑陋的代码
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define inf 0x3f3f3f3f
#define maxn 100
#define Abs(a) ((a)>0?(a):-(a))
int val[6];
int qulility[6];
struct obje{
int w[5];
int value;
}obj[100];
int dp[6][6][6][6][6];
int main()
{
int n,t,x;
int c,qu,value;
while(cin>>n){
mst(dp,inf);
mst(obj,0);
mst(qulility,0);
mst(val,0);
map<int,int> ob;
int i,j;
for(i=0;i<n;i++){
cin>>c>>qu>>value;
ob[c]=i;
val[i]=value;
qulility[i]=qu;
obj[i].w[i]=1;
obj[i].value=value;
}
cin>>t;
for(j=i;j<t+i;j++){
cin>>x; int a,b;
for(int k=0;k<x;k++){
cin>>a>>b;
obj[j].w[ ob[a]]=b;
}
cin>>x;
obj[j].value=x;
}
dp[0][0][0][0][0]=0;
for(int i=0;i<j;i++)
for(int k=0;k<=qulility[0];k++)
for(int l=0;l<=qulility[1];l++)
for(int m=0;m<=qulility[2];m++)
for(int n=0;n<=qulility[3];n++)
for(int o=0;o<=qulility[4];o++){
if(k>=obj[i].w[0]&&l>=obj[i].w[1]&&m>=obj[i].w[2]&&n>=obj[i].w[3]&&o>=obj[i].w[4])
dp[k][l][m][n][o]=min(dp[k][l][m][n][o],dp[k-obj[i].w[0]][l-obj[i].w[1]][m-obj[i].w[2]][n-obj[i].w[3]][o-obj[i].w[4]]+obj[i].value);
}
cout<<dp[qulility[0]][qulility[1]][qulility[2]][qulility[3]][qulility[4]];
}
return 0;
}
POJ 1170 Shopping Offers非状态压缩做法的更多相关文章
- HDU 1170 Shopping Offers 离散+状态压缩+完全背包
题目链接: http://poj.org/problem?id=1170 Shopping Offers Time Limit: 1000MSMemory Limit: 10000K 问题描述 In ...
- 背包系列练习及总结(hud 2602 && hdu 2844 Coins && hdu 2159 && poj 1170 Shopping Offers && hdu 3092 Least common multiple && poj 1015 Jury Compromise)
作为一个oier,以及大学acm党背包是必不可少的一部分.好久没做背包类动规了.久违地练习下-.- dd__engi的背包九讲:http://love-oriented.com/pack/ 鸣谢htt ...
- poj 1170 Shopping Offers
Shopping Offers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4696 Accepted: 1967 D ...
- POJ 1170 Shopping Offers -- 动态规划(虐心的六重循环啊!!!)
题目地址:http://poj.org/problem?id=1170 Description In a shop each kind of product has a price. For exam ...
- poj - 1170 - Shopping Offers(减少国家dp)
意甲冠军:b(0 <= b <= 5)商品的种类,每个人都有一个标签c(1 <= c <= 999),有需要购买若干k(1 <= k <=5),有一个单价p(1 & ...
- POJ 1170 Shopping Offers(完全背包+哈希)
http://poj.org/problem?id=1170 题意:有n种花的数量和价格,以及m种套餐买法(套餐会便宜些),问最少要花多少钱. 思路:题目是完全背包,但这道题目不好处理的是套餐的状态, ...
- POJ - 1170 Shopping Offers (五维DP)
题目大意:有一个人要买b件商品,给出每件商品的编号,价格和数量,恰逢商店打折.有s种打折方式.问怎么才干使买的价格达到最低 解题思路:最多仅仅有五种商品.且每件商品最多仅仅有5个,所以能够用5维dp来 ...
- poj - 3254 - Corn Fields (状态压缩)
poj - 3254 - Corn Fields (状态压缩)超详细 参考了 @外出散步 的博客,在此基础上增加了说明 题意: 农夫有一块地,被划分为m行n列大小相等的格子,其中一些格子是可以放牧的( ...
- POJ 1691 Painting a Board(状态压缩DP)
Description The CE digital company has built an Automatic Painting Machine (APM) to paint a flat boa ...
随机推荐
- Linux下修改efi启动项
Linux下有一个efibootmgr工具可以编辑efi启动项,十分方便,简单介绍如下 直接运行efibootmgr会显示出当前所有efi启动项,每个启动项前都有相应编号, 可以使用efibootmg ...
- webstorm 永久激活方法
打开终端,执行: cd /etc/ sudo vim hosts 在最后一行加上: 0.0.0.0 account.jetbrains.com 打开webstorm,选择Activation Code ...
- 2020-3-15 20175110王礼博 Exp2后门原理与实践
目录 1.使用netcat获取主机操作Shell,cron启动 2.使用socat获取主机操作Shell, 任务计划启动 3.使用MSF meterpreter(或其他软件)生成可执行文件,利用nca ...
- 广告行业中那些趣事系列9:一网打尽Youtube深度学习推荐系统
最新最全的文章请关注我的微信公众号:数据拾光者. 摘要:本篇主要分析Youtube深度学习推荐系统,借鉴模型框架以及工程中优秀的解决方案从而应用于实际项目.首先讲了下用户.广告主和抖音这一类视频平台三 ...
- tcp长连接、短连接、连接池的思考
在基于tcp的 rcp实现方式中,有如下几种选择: 1. 长连接:同步和异步方式. 同步方式下客户端所有请求共用同一连接,在获得连接后要对连接加锁,在读写结束后才解锁释放连接,性能低下,基本很少采用, ...
- Property [*****] not found on type [com.erp.pojo.ErpSupplier]
我实体类里用的是 springboot 里@Slf4j @Data 注解式写的 这样可以减少代码量 ,但是遇到一个问题影响我好长时间 出现了这个错误 Property [*****] not ...
- 化繁为简,弱监督目标定位领域的新SOTA - 伪监督目标定位方法(PSOL) | CVPR 2020
论文提出伪监督目标定位方法(PSOL)来解决目前弱监督目标定位方法的问题,该方法将定位与分类分开成两个独立的网络,然后在训练集上使用Deep descriptor transformation(DDT ...
- TcxLookupComboBox
1.绑定数据源显示 cxLookupComboBox1.Properties.DropDownAutoSize:=true; //设置下拉列表为自适应宽度 cxLookupComboBox1.Prop ...
- 阿里Canal框架数据库同步-实战教程
一.Canal简介: canal是阿里巴巴旗下的一款开源项目,纯Java开发.基于数据库增量日志解析,提供增量数据订阅&消费,目前主要支持了MySQL(也支持mariaDB). 二.背景介绍: ...
- Jmeter发送jdbc请求进行大批量造数
创建批量造数脚本,一个简单的结构如下图所示, 1.线程组(10个线程重复运行2次,相当于造20个数) 2.用户定义变量(这是全局变量,用于后面随机筛选用) 3.数据库连接配置 4.计数器(用于主键递增 ...