TZOJ 2289 Help Bob(状压DP)
描述
Bob loves Pizza but is always out of money. One day he reads in the newspapers that his favorite pizza restaurant, Alfredo's Pizza Restaurant, is running a competition: they will donate a big pizza to the first person who will tell them the lowest price per area that can be achieved by buying any of the pizzas at most once. "That task is easy!", thinks Bob, "For each pizza I just calculate the average price and the lowest quotient will be the answer.".
Unfortunately the problem is a bit more complicated: with some pizzas Alberto gives out discount coupons for getting another pizza cheaper and even worse, those coupons can be combined. The pizzas have to be bought one after the other, and it is not possible to use a coupon to get a discount retrospectively for a pizza which has already been bought. Can you help Bob to become the first to solve this task and to get a pizza for free?
输入
The input file contains several test cases. Each test case starts with a number m, the number of pizzas Alfredo offers. Input is terminated by m = 0. Otherwise, 1 ≤ m ≤ 15. Then follow m lines describing the pizzas. Each of those following lines describes pizza i (1 ≤ i ≤ m) and starts with 3 integer numbers pi, ai and ni specifying the price of the pizza, its area and the number of discount coupons you get when buying it, 1 ≤ pi ≤ 10000, 1 ≤ ai ≤ 10000 and 0 ≤ ni < m. Then follow ni pairs of integer numbers xi,j and yi,j specifying the index xi,j (1 ≤ xi,j ≤ m, xi,j ≠ i) of the pizza you get a discount coupon for and the discount in percentage terms yi,j (1 ≤ yi,j ≤ 50) you get when buying pizza xi,j. You may assume that for each i the values xi,j are pairwise distinct.
输出
For each test case print one line containing the lowest price per area that can be achieved by buying any of the pizzas at most once. Round this number to 4 places after the decimal point. Note that you can combine an arbitrary number of discount coupons: for a pizza with price 10 and two rabatt coupons for that pizza with a 50 and a 20 on it, you would only have to pay 10 * 0.8 * 0.5 = 4 monetary units.
样例输入
1
80 30 0
2
200 100 1 2 50
200 100 0
5
100 100 2 3 50 2 50
100 100 1 4 50
100 100 1 2 40
600 600 1 5 10
1000 10 1 1 50
0
样例输出
2.6667
1.5000
0.5333
题意
N个披萨,p价格a面积k送的优惠券数,接着k个代表买x披萨打10-y/10折
每个披萨最多买1个,问怎么买总价格/总面积最大,并输出值
题解
状压DP
dp[i]代表买了i中二进制为1的披萨花的最少钱
那么答案就是min(dp[i]/状态i中二进制为1的披萨总面积)
代码
#include<bits/stdc++.h>
using namespace std; const int N=(<<);
int main()
{
int n,p[],a[],k[],x[][];
double dp[N],y[][];
while(scanf("%d",&n)!=EOF,n)
{
for(int i=;i<<<n;i++)dp[i]=1e18;
for(int i=;i<n;i++)
{
scanf("%d%d%d",&p[i],&a[i],&k[i]);
for(int j=;j<k[i];j++)
{
scanf("%d%lf",&x[i][j],&y[i][j]);
x[i][j]--;
y[i][j]=-y[i][j]/;
}
}
int state=<<n;
double minn=1e18;
dp[]=;
for(int i=;i<state;i++)
{
double co[],area=;
for(int j=;j<n;j++)co[j]=.;
for(int j=;j<n;j++)
if(i&(<<j))
{
area+=a[j];
for(int l=;l<k[j];l++)
co[x[j][l]]*=y[j][l];
}
for(int j=;j<n;j++)
{
if(i&(<<j))continue;
dp[i|(<<j)]=min(dp[i|(<<j)],dp[i]+p[j]*co[j]);
minn=min(minn,dp[i|(<<j)]/(area+a[j]));
}
}
printf("%.4f\n",minn);
}
return ;
}
TZOJ 2289 Help Bob(状压DP)的更多相关文章
- TZOJ 4912 炮兵阵地(状压dp)
描述 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P" ...
- hdu 4856 Tunnels (bfs + 状压dp)
题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line ...
- HDU-4856 Tunnels (BFS+状压DP)
Problem Description Bob is travelling in Xi’an. He finds many secret tunnels beneath the city. In hi ...
- HDU 4778 状压DP
一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...
- HDU3811 Permutation —— 状压DP
题目链接:https://vjudge.net/problem/HDU-3811 Permutation Time Limit: 6000/3000 MS (Java/Others) Memor ...
- BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3336 Solved: 1936[Submit][ ...
- nefu1109 游戏争霸赛(状压dp)
题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...
- poj3311 TSP经典状压dp(Traveling Saleman Problem)
题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...
- [NOIP2016]愤怒的小鸟 D2 T3 状压DP
[NOIP2016]愤怒的小鸟 D2 T3 Description Kiana最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于(0,0)处,每次Kiana可 ...
随机推荐
- http/https协议
HTTP 1. 概念 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览 ...
- Windows 10(UWP)开发技巧 - PageUserControl
[本系列需要具有一定开发基础] 我们在开发中经常遇到这样的场景: 1.呈现详细信息,且包含一些操作.如:查看原图,支持放大,缩小,多图. 2.执行特定的行为,且要有回执结果.如:选择联系人,选中某图, ...
- Ubuntu下把缺省的dash shell修改为bash shell
Ubuntu下缺省使用的是shell是dash,而不是bash.从/bin/sh软连接的指向可以看出这点. dash shell 虽然比bash shell更轻便,但是它并不支持所有的语法,运行she ...
- 用SVG做background image
1 用utf8格式, 需要 双引号“”替换为单引号,而且采用url encode编码,例如# 替换为 %23, body { background-image: url("data:imag ...
- <<让你自己的APP成为系统应用>>所遇到的问题及解决方法
1.adb connect 10.100.1.772.adb -s 10.100.1.77 shell remount3.让你自己的APP成为系统应用 adb push xxx.apk system/ ...
- 微信小程序隐藏滚动条
全局wxss中添加以下样式,可以隐藏所有的滚动条: 包括使用scroll-view组件或者使用overflow-y:scroll;而出现的滚动条: 无论竖向横向滚动条都可隐藏: ::-webkit-s ...
- Python全栈开发记录_第九篇(面向对象(类)的学习)
有点时间没更新博客了,今天就开始学习类了,今天主要是面向对象(类),我们知道面向对象的三大特性,那就是封装,继承和多态.内容参考该博客https://www.cnblogs.com/wupeiqi/p ...
- Android 开发 Camera类的拍照与录像
前言 在开发Android应用的时候,如果需要调用摄像头拍照或者录像,除了通过Intent调用系统现有相机应用进行拍照录像之外,还可以通过直接调用Camera硬件去去获取摄像头进行拍照录像的操作.本篇 ...
- Anatomy of a Database System学习笔记 - 存储管理
使用裸设备,还是使用文件系统? 描述 pros cons 裸设备 顺序读磁盘快比随机要快10-100倍,DB比OS更懂磁盘负载,因此很多DB是直接管理数据块如何存放的. DB对裸设备的管理,比文件 ...
- Ping++支付
第一次接触支付啊,有点小激动,所以写下这篇随笔以防以后忘记. ping++的文档还有服务都是挺好的,当你注册之后,就会给你发邮件.截图如下: 是不是感觉服务很不错. 接下来直入正题. 首先,我们需要加 ...