Shopping Offers
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4696   Accepted: 1967

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

此题用到6进制表示物品。吧套餐也看作是物品,这里用6进制将他们区分开。然后就老实背包。
#include <stdio.h>
#include <string.h>
#pragma warning(disable:4996)
int b,c,k,p,s,n, a[], v[],w[];
int dp[+],id[],sum;
int main()
{
while (~scanf("%d", &b))
{
int six = ;
sum = ;
memset(id, -, sizeof id);
for (int i = ; i < b; i++)
{
scanf("%d%d%d", &c, &k, &p);
id[c] = i;
a[i] = k;
w[i] = six;
v[i] = p;
sum += w[i] * a[i];
six *= ;
}
for (int i = ; i <= sum; i++)dp[i] = << ;
scanf("%d", &s);
while (s--)
{
a[b] = <<;
w[b] = ;
scanf("%d", &n);
int s = ;
for (int i = ; i < n; i++)
{
scanf("%d%d", &c, &k);
if (id[c] == -)continue;
a[b] = a[b] < a[id[c]] / k ? a[b] : a[id[c]] / k;
w[b] += k*w[id[c]];
s += k*v[id[c]];
}
if (a[b] == <<)a[b] = ;
scanf("%d", &p);
v[b] = s<p?s:p;
b++;
}
for (int i = ; i < b; i++)
for (int k = ; k < a[i]; k++)
for (int j = sum; j >= w[i]; j--)
{
if (dp[j] > dp[j - w[i]] + v[i])dp[j] = dp[j - w[i]] + v[i];
}
printf("%d\n", dp[sum]);
//for (int i = 0; i <= sum; i++) printf("%d\n", dp[i]);
}
}

poj 1170 Shopping Offers的更多相关文章

  1. 背包系列练习及总结(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 ...

  2. POJ 1170 Shopping Offers非状态压缩做法

    Shopping Offers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5659 Accepted: 2361 Descr ...

  3. POJ 1170 Shopping Offers -- 动态规划(虐心的六重循环啊!!!)

    题目地址:http://poj.org/problem?id=1170 Description In a shop each kind of product has a price. For exam ...

  4. poj - 1170 - Shopping Offers(减少国家dp)

    意甲冠军:b(0 <= b <= 5)商品的种类,每个人都有一个标签c(1 <= c <= 999),有需要购买若干k(1 <= k <=5),有一个单价p(1 & ...

  5. POJ 1170 Shopping Offers(完全背包+哈希)

    http://poj.org/problem?id=1170 题意:有n种花的数量和价格,以及m种套餐买法(套餐会便宜些),问最少要花多少钱. 思路:题目是完全背包,但这道题目不好处理的是套餐的状态, ...

  6. POJ - 1170 Shopping Offers (五维DP)

    题目大意:有一个人要买b件商品,给出每件商品的编号,价格和数量,恰逢商店打折.有s种打折方式.问怎么才干使买的价格达到最低 解题思路:最多仅仅有五种商品.且每件商品最多仅仅有5个,所以能够用5维dp来 ...

  7. HDU 1170 Shopping Offers 离散+状态压缩+完全背包

    题目链接: http://poj.org/problem?id=1170 Shopping Offers Time Limit: 1000MSMemory Limit: 10000K 问题描述 In ...

  8. 洛谷P2732 商店购物 Shopping Offers

    P2732 商店购物 Shopping Offers 23通过 41提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交  讨论  题解 最新讨论 暂时没有讨论 题目背景 在商店中, ...

  9. USACO 3.3 Shopping Offers

    Shopping OffersIOI'95 In a certain shop, each kind of product has an integer price. For example, the ...

随机推荐

  1. Vi和Vim的区别及联系

    它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅兼容vi的所有指令,而且还有一些新的特性在里面.vim的这些优势主要体现在以下几个方面:1.多级撤消我们知道在vi里,按 u只能撤消上次命 ...

  2. c语言的label后面不能直接跟变量申明

    ; goto JUMP; printf("x is : %d\n",x); JUMP: ; <=== 错误,lable后面不能申明变量,只能是表达式语句(statement) ...

  3. solr4.0.0学习(二) 数据库导入clob与blob为索引

    导入clob很简单.但是blob好像没有提供方法,所以改了一下源码,重新编译替换class文件,竟然成功了. 先把配置文件贴上 SCHEMA.XML <?xml version="1. ...

  4. ASP.NET- web.config配置用户出错页

    很简单,刚好用到,收藏 RemoteOnly是自定义用户错误,改成On,将所有错误都不让用户看见 每当用户访问错误页面时,会出现不友好的404错误,所以为了防止这种不友好,我们在web.config中 ...

  5. SpringNote02.Blog系统迁移到Linux下

    基于SpringMVC-Hibernate的博客系统还在继续开发中 . 项目地址:https://github.com/defshine/SpringBlog 整个项目迁移到linux下开发,安装in ...

  6. C#通过FTP账号上传、修改、删除文件 FTPClient

    下面类文件中,主要做的工作是:从ftp服务器上下载文件把本地文件替换.添加.或删除功能,在替换本地文件时会先备份一下本地的文件,若整个操作都完成了就会发出commit命令,表示全部替换成功.若中间操作 ...

  7. RichtextBox去除闪烁光标

    http://files.cnblogs.com/xe2011/CustomRichTextBox_HideCaret.rar richTextBox能高亮选择,光标仍在,没有光标闪烁 把重RichT ...

  8. onInterceptTouchEvent和onTouchEvent调用时序

    onInterceptTouchEvent()是ViewGroup的一个方法,目的是在系统向该ViewGroup及其各个childView触发onTouchEvent()之前对相关事件进行一次拦截,A ...

  9. JavaRTS-DTraceProvider

    https://docs.oracle.com/javase/realtime/doc_2.0_u1/release/JavaRTSDTraceProvider.html

  10. spring beans源码解读之--XmlBeanFactory

    导读: XmlBeanFactory继承自DefaultListableBeanFactory,扩展了从xml文档中读取bean definition的能力.从本质上讲,XmlBeanFactory等 ...