描述

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 ≤ im) 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,jm, xi,ji) 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)的更多相关文章

  1. TZOJ 4912 炮兵阵地(状压dp)

    描述 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P" ...

  2. hdu 4856 Tunnels (bfs + 状压dp)

    题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line ...

  3. HDU-4856 Tunnels (BFS+状压DP)

    Problem Description Bob is travelling in Xi’an. He finds many secret tunnels beneath the city. In hi ...

  4. HDU 4778 状压DP

    一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...

  5. HDU3811 Permutation —— 状压DP

    题目链接:https://vjudge.net/problem/HDU-3811 Permutation Time Limit: 6000/3000 MS (Java/Others)    Memor ...

  6. BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]

    1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3336  Solved: 1936[Submit][ ...

  7. nefu1109 游戏争霸赛(状压dp)

    题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...

  8. poj3311 TSP经典状压dp(Traveling Saleman Problem)

    题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...

  9. [NOIP2016]愤怒的小鸟 D2 T3 状压DP

    [NOIP2016]愤怒的小鸟 D2 T3 Description Kiana最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于(0,0)处,每次Kiana可 ...

随机推荐

  1. 2018秋寒假作业5—PTA编程总结2

    1.实验代码: 7-1 币值转换 (20 分) 输入一个整数(位数不超过9位)代表一个人民币值(单位为元),请转换成财务要求的大写中文格式.如23108元,转换后变成"贰万叁仟壹百零捌&qu ...

  2. js实时显示鼠标坐标

    <!DOCTYPE html><html><head>    <meta charset="utf-8">    <title ...

  3. spark2.1源码分析1:Win10下IDEA源码阅读环境的搭建

    环境:win10.IDEA2016.3.maven3.3.9.git.scala 2.11.8.java1.8.0_101.sbt0.13.12 下载: #git bash中执行: git clone ...

  4. Ubuntu下安装Snap

    介绍 Snap是一个全新的软件包架构,它与其它包管理器的区别在于snap安装的app互相之间是高度隔离的,减少了互相引用. 避免了很多冲突问题. 不过这也导致了其占用的磁盘比较多. 安装 apt in ...

  5. [java,2019-01-25] 图片和二进制互转

    import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOu ...

  6. python2 with open(path,"",) as f:

    python2 with open 没有 encoding 这个参数 会报错, 可以 import io with io.open(path,"") as f: 这样就ok 或者是 ...

  7. 代码:PC CSS(工作中用)

    常规内容区域的:标题和文字 2016-5-23 .p16{font-size:16px;color:#333;}/* 16号#333的标题 */ .p12-gray{font-size:16px;co ...

  8. Jprofiler监控远程jvm

    2.Windows打开安装好的jprofiler 1 3.配置步骤: vi catalina.sh 添加复制的配置保存退出后重新停启Tomcatsh shutdown.sh #停ps -ef|grep ...

  9. Git上传本地代码

    Git  add  .将本地文件上传至缓冲区 git   commit  -m  'project  init'  将代码上传至本地仓库 Git   push   将本地的代码传至线上(码云) git ...

  10. Python第3天

    字符串的魔法: expandtabs 可用来制表 当前输入是否为数字:isdecimal 最低级 isdigit 支持特殊数字 isnumeric 支持中文 标识符 isidentifier 是否存在 ...