poj 1170 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
Output
Sample Input
2
7 3 2
8 2 5
2
1 7 3 5
2 7 1 8 2 10
Sample Output
14
Source
#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的更多相关文章
- 背包系列练习及总结(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: 5659 Accepted: 2361 Descr ...
- 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来 ...
- HDU 1170 Shopping Offers 离散+状态压缩+完全背包
题目链接: http://poj.org/problem?id=1170 Shopping Offers Time Limit: 1000MSMemory Limit: 10000K 问题描述 In ...
- 洛谷P2732 商店购物 Shopping Offers
P2732 商店购物 Shopping Offers 23通过 41提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交 讨论 题解 最新讨论 暂时没有讨论 题目背景 在商店中, ...
- USACO 3.3 Shopping Offers
Shopping OffersIOI'95 In a certain shop, each kind of product has an integer price. For example, the ...
随机推荐
- ubuntu Server LAmp环境
1. LAMP 的安装 sudo apt-get install apache2 mysql-server mysql-client php5 php5-gd php5-mysql 由于LAMP大部分 ...
- weekend110(Hadoop)的 第四天笔记
(2015年1月18日) 课程目录 01-复习 02-hadoop中的序列化机制 03-流量求和mr程序开发 04-hadoop的自定义排序实现 05-mr程序中自定义分组的实现 06-shuffle ...
- 升级OpenSSH详细步骤
由于系统扫描到OpenSSH版本太低,所以需要将其升级到高版本.网上搜罗数个文章,都多多少少有点疏漏.加上自己之前没升级过SSH,参考好几个文章查缺补漏才升级成功,着实废了不少劲儿.所以综合一下前辈们 ...
- Oracle DB 备份和恢复的概念
• 确定Oracle DB 中可能发生的故障类型 • 说明优化实例恢复的方法 • 说明检查点.重做日志文件和归档日志文件的重要性 • 配置快速恢复区 • 配置ARCHIVELOG模式 部分工作内容 ...
- mybatis10 实现类代理对象开发
mapper实现类代理对象开发 要想让mybatis自动创建dao接口实现类的代理对象,必须遵循一些规则: SqlSession sqlSession = sqlSessionFactory.open ...
- NVMe 图解
http://www.ssdfans.com/?p=1143#rd&sukey=3997c0719f151520989740bb972a716fdb2dbab623808d16acd5075b ...
- 【转】Enable ARC in a Cocos2D Project: The Step-by-Step-How-To-Guide Woof-Woof!
On April 5, 2012, in idevblogaday, by Steffen Itterheim http://www.learn-cocos2d.com/2012/04/enablin ...
- react native web
http://rawgit.com/taobaofed/react-web/master/pages/uiexplorer.html#/scene_1?_k=7vm99j
- 【php】中【event】之实现方式
这两天看了点事件机制,那么在php中,如何实现最简单的事件呢? 废话不多说,我们上代码. <?php class Event{ //事件名称 public $name; //存储hander p ...
- 高效删除 ListItem
The most efficient way to a lot of transaction in SharePoint is using of SPWeb.ProcessBatchData meth ...