博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1170 Shopping Offers
阅读量:5014 次
发布时间:2019-06-12

本文共 3619 字,大约阅读时间需要 12 分钟。

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

27 3 28 2 521 7 3 52 7 1 8 2 10

Sample Output

14

Source

此题用到6进制表示物品。吧套餐也看作是物品,这里用6进制将他们区分开。然后就老实背包。
#include 
#include
#pragma warning(disable:4996)int b,c,k,p,s,n, a[200], v[200],w[200];int dp[200000+20],id[1000],sum;int main(){ while (~scanf("%d", &b)) { int six = 1; sum = 0; memset(id, -1, sizeof id); for (int i = 0; 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 *= 6; } for (int i = 1; i <= sum; i++)dp[i] = 1 << 28; scanf("%d", &s); while (s--) { a[b] = 1<<28; w[b] = 0; scanf("%d", &n); int s = 0; for (int i = 0; i < n; i++) { scanf("%d%d", &c, &k); if (id[c] == -1)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] == 1<<28)a[b] = 0; scanf("%d", &p); v[b] = s
= 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]); }}

 

转载于:https://www.cnblogs.com/newadi/p/4750885.html

你可能感兴趣的文章
android中不同版本兼容包的区别
查看>>
Static 与 new 的问题【待解决】
查看>>
xml
查看>>
在 mvc4 WebApi 中 json 的 跨域访问
查看>>
敏捷开发文章读后感
查看>>
xposed获取context 的方法
查看>>
html5 canvas 图像处理
查看>>
He who hesitates is Lost
查看>>
php中引用&的真正理解-变量引用、函数引用、对象引用
查看>>
关于<form> autocomplete 属性
查看>>
OutOfMemory
查看>>
LeetCode:组合总数III【216】
查看>>
Thinkphp框架回顾(三)之怎么实现平常的sql操作数据库
查看>>
虚函数的效率问题
查看>>
POJ 1860 Currency Exchange(SPFA 判断有无“正”环)
查看>>
广告地址屏蔽
查看>>
收缩SqlServer数据库日记方法
查看>>
每日英语:15 places to find inspiration
查看>>
学习方法--提问
查看>>
【转】每天一个linux命令(3):pwd命令
查看>>