POJ 1170 Shopping Offers(完全背包+哈希)
http://poj.org/problem?id=1170
题意:
有n种花的数量和价格,以及m种套餐买法(套餐会便宜些),问最少要花多少钱。
思路:
题目是完全背包,但这道题目不好处理的是套餐的状态,因为数量最多只有5,所有可以用6进制来记录状态。
最后的话就是一个完全背包啦~
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e4 + ; int n, m;
int v; struct node
{
int code, st, num, price;
}a[maxn]; map<int,int> ID; int d[maxn]; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n))
{
v=;
ID.clear(); for(int i=;i<n;i++)
{
scanf("%d%d%d",&a[i].code,&a[i].num,&a[i].price);
a[i].st=pow(6.0,(double)i);
v+=a[i].st*a[i].num;
ID[a[i].code]=i;
} scanf("%d",&m);
for(int i=;i<m;i++)
{
int t;
scanf("%d",&t);
a[i+n].st=;
while(t--)
{
int code, num;
scanf("%d%d",&code,&num);
if(ID.find(code)==ID.end()) continue;
a[i+n].st+=a[ID[code]].st*num;
}
scanf("%d",&a[i+n].price);
} for(int i=;i<=v;i++)
d[i]=INF;
d[]=; for(int i=;i<n+m;i++)
{
for(int j=a[i].st;j<=v;j++)
{
d[j]=min(d[j],d[j-a[i].st]+a[i].price);
}
}
printf("%d\n",d[v]);
}
return ;
}
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: 4696 Accepted: 1967 D ...
- 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 (五维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 ...
随机推荐
- chrome单步调试代码
单步调试代码 所有步骤选项均通过边栏中的可点击图标 表示,但也可以通过快捷键触发(鼠标悬停在操作图标上就可以看到快捷键).下面是简要介绍: 图标/按钮 操作 描述 Resume 继续执行直到下一个断点 ...
- pta 习题集5-19 列车厢调度
1 ====== <--移动方向 / 3 ===== \ 2 ====== -->移动方向 大家或许在某些数据结构教材上见到过"列车厢调度问题"(当然没见过也不要紧). ...
- Ubuntu安装pycurl
转自:https://blog.csdn.net/qq_23729557/article/details/78836547 在Ubuntu 16.04上安装pycurl时大致会遇到一下两个问题: 在使 ...
- timedatectl — Control the system time and date
timedatectl --help 的执行结果如下: timedatectl [OPTIONS...] COMMAND ... Query or change system time and dat ...
- MySQL两大存储引擎:MyISAM和InnoDB
Mysql有两大常用的存储引擎MyISAM,InnoDB,默认的形式是前者. 两者基本的差别是对事务处理.外键和行级锁的主持上,InnoDB支持事务处理.外键等高级特性,而MyISAM不支持.MyIS ...
- Python开发【模块】:Concurrent
concurrent 模块 回顾: 对于python来说,作为解释型语言,Python的解释器必须做到既安全又高效.我们都知道多线程编程会遇到的问题,解释器要留意的是避免在不同的线程操作内部共享的数据 ...
- django的cache
使用文件缓存 #settings.py CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.filebased.F ...
- HTTP错误 404.17–Not Found 请求的内容似乎是脚本,因而将无法有静态文件处理程序来处理
解决方案:切换应用程序池的模式.
- centos LAMP第三部分php,mysql配置 php配置文件 配置php的error_log 配置php的open_basedir 安装php的扩展模块 phpize mysql配置第二十一节课
centos LAMP第三部分php,mysql配置 php配置文件 配置php的error_log 配置php的open_basedir 安装php的扩展模块 phpize mysql配 ...
- Atom预览markdown插件Markdown Preview Enhanced
atom 上目前最强的 markdown 插件Markdown Preview Enhanced 是一款为 ATOM 编辑器编写的超级强大的 Markdown 插件.这款插件意在让你拥有飘逸的 Mar ...