题目链接:

http://poj.org/problem?id=1170

Shopping Offers

Time Limit: 1000MS
Memory Limit: 10000K
#### 问题描述
> 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.

输入

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.

输出

Your program is to write to standard output. Output one line with the lowest possible price to be paid.

样例输入

2

7 3 2

8 2 5

2

1 7 3 5

2 7 1 8 2 10

样例输出

14

题意

告诉你每类产品的单价,和打算购买的数量。现在有些优惠活动,买一些特定数量的商品组合能够优惠,问你如何用最少的钱买到需要购买的商品。

题解

dp[i][j][k][l][m]代表购买了i个商品0...m个商品4,需要花的最少的money,然后每个优惠活动和单价都可以看作转移边。前面那个状态可以用六进制压缩下状态。

这样转化成了一个完全背包的额问题了。

代码

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<sstream>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII; const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
const double PI = acos(-1.0); //start---------------------------------------------------------------------- const int maxn=7800; struct In {
int id,c,v;
bool operator < (const In& tmp) const {
return id<tmp.id;
}
} in[11]; int dp[maxn],a[11],b[11],xp[11]; int main() {
xp[0]=1; for(int i=1;i<11;i++) xp[i]=xp[i-1]*6;
int n,m;
while(scf("%d",&n)==1) {
VI ha;
VPII arr;
for(int i=0; i<n; i++) {
scf("%d%d%d",&in[i].id,&in[i].c,&in[i].v);
ha.pb(in[i].id);
} sort(all(ha));
sort(in,in+n); int last=0;
for(int i=0;i<n;i++){
last+=xp[i]*in[i].c;
arr.pb(mkp(xp[i],in[i].v));
} scf("%d",&m);
for(int i=0;i<m;i++){
int cnt; scf("%d",&cnt);
int stat=0;
while(cnt--){
int id,c;
scf("%d%d",&id,&c);
int p=lower_bound(all(ha),id)-ha.begin();
stat+=c*xp[p];
}
int v; scf("%d",&v);
arr.pb(mkp(stat,v));
} clr(dp,-1);
dp[0]=0;
for(int i=1;i<=last;i++){
for(int j=0;j<arr.sz();j++){
int stat=arr[j].X,v=arr[j].Y;
if(i-stat>=0&&dp[i-stat]>=0){
if(dp[i]==-1) dp[i]=dp[i-stat]+v;
else dp[i]=min(dp[i],dp[i-stat]+v);
}
}
} prf("%d\n",dp[last]); }
return 0;
} //end-----------------------------------------------------------------------

最新文章

  1. jupyter nb + scite 混合搭建成我的最爱IDE
  2. 17、文案人员 - IT软件人员书籍系列文章
  3. MySQL复制表结构表数据
  4. 电Call记录统计查询sql
  5. wikioi 3038 3n+1问题
  6. ActionBarCompat
  7. openoffice转换过程中遇到繁体字文档转换失败的问题
  8. Eclipse 在线汉化
  9. 错误: libstdc++.so.6: cannot open shared object file: No such file or directory
  10. Brackets - 强大免费的开源跨平台Web前端开发工具IDE (HTML/CSS/Javascript代码编辑器)
  11. [Codeforces]852A - Digits
  12. [NOIp2013普及组]车站分级
  13. 基于树莓派3的CAN总线编程
  14. Controllerizing the ScrollViewer Thumbnail
  15. FPKM\RPKM\TPM学习[转载]
  16. 【转】Android Shape绘制虚线在手机端查看是实线的问题
  17. DGbroker故障切换示例
  18. 第一篇 对Javascript中原型的深入理解
  19. MongoDB 学习 第八节 驱动实践
  20. Go语言 关键字:defer

热门文章

  1. iview 或 element-ui table 列表表头加样式
  2. C++学习第一天(helloword)
  3. 如何保障Go语言基础代码质量?
  4. 开发自己的DataSet查看器
  5. (收藏)mci 录音和播放
  6. VC编译连接选项详解
  7. Python面向对象之封装、property特性、绑定方法与非绑定方法
  8. SSISDB2:SSIS工程的操作实例
  9. [webpack]-webpack超级详细搭建实用前端环境
  10. Vue渲染数据理解以及Vue指令