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;
}

最新文章

  1. 单据UI界面设计开发
  2. HD1599 find the mincost route(floyd + 最小环)
  3. 上海SAP代理商 服装行业ERP系统 达策SAP金牌代理商
  4. nginx支持cgi(c,c++)
  5. mysql 导出过长的数字列时变科学计数法问题解决办法
  6. 【Unity3D基础教程】给初学者看的Unity教程(七):在Unity中构建健壮的单例模式(Singleton)
  7. C/C++笔试题目
  8. php删除html标签的三种解决方法
  9. poj1163 dp入门
  10. ORA-01092 ORA-12432: LBAC error: zllegnp:OCIStmtExecute 故障一例
  11. linux添加到普通用户sudo才干
  12. 设计模式-GoF23
  13. 2.8. 创建 NSManagedObject 的子类 (Core Data 应用程序实践指南)
  14. 你的外接键盘的小键盘在Num Lock键亮着的,但是数字按了不能用,解决办法在这里
  15. 2017年 JavaScript 框架回顾 -- 后端框架
  16. vs2017打包安卓项目简述
  17. 自然语言处理(nlp)比计算机视觉(cv)发展缓慢,而且更难!
  18. 201621123002《java程序设计》第九周学习总结
  19. 在windows下如何快速搭建web.py开发框架
  20. css学习_css盒模型及应用

热门文章

  1. Golang Web入门(1):自顶向下理解Http服务器
  2. OS-DOS/CMD/Windows/各类软件快捷键等使用总结
  3. 01-启动jmeter目录功能
  4. 一个不错的intellj 相关的博客
  5. 视频图文教学 - 用最快的速度把 DotNet Core Blazor 程序安装到 树莓派中 并且用网页控制 GPIO 闪灯
  6. webWMS开发过程记录(四)- 整体设计
  7. vue中 使用SVG实现鼠标点击绘图 提示鼠标移动位置 显示绘制坐标位置
  8. Youtube推荐算法的前世今生
  9. TokenMismatchException Laravel
  10. C#多线程(13):任务基础①