描述

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. Git操作相关记录

    1. 本地更新fork来的项目,与原项目同步更新 git remote add upstream <origin_repo_addr> git remote -v git fetch up ...

  2. Pycharm去掉项目所有 # 注释

    通过快捷键ctrl+shift+R 进入 项目全局替换窗口,点击右上角 勾选正则,然后 搜索框输入 (#.*) 即可 ,然后点击 replace all 去掉所有注释

  3. jersey 用FastJson替换掉默认的Jackson

    @Bean public ResourceConfig resourceConfig() { ResourceConfig resourceConfig = new ResourceConfig(); ...

  4. djiango 虚拟环境与项目创建

    建立虚拟环境 一,查看有那些虚拟环境 :workon 二,创建虚拟环境:mkvirtualenv -p/usr/bin/python3 django(p后面是路径) 三,进入虚拟环境:workon d ...

  5. django 之 ContentType的使用

    1. ContentType 是干什么用的呢: 1. ContentType: 主要的作用就是Django orm的创建表的时候,可以方便多表查询使用,简化多表查询的过程 2.ContentType ...

  6. activiti官网实例项目activiti-explorer之扩展流程节点属性2

    情景需求:需要查找activiti-explorer项目中获取流程id的方法,然后根据流程id获取相应字段在节点属性中添加内容. 大致流程:拿取整个流程id获取对应表单属性,在页面节点属性中展示对应表 ...

  7. Hibernate 中出现 users is not mapped 问题

    Hibernate 中出现 users is not mapped 问题: 解答:HQL语句中表名应该是ORM映射的类名,所以应该改成:  (如果是用注解生成实体类,那就是注解的那个类)String ...

  8. 关于Eclipse for Python

    学习Python一段时间,一直用Python的IDE进行开发,过程蛮顺利,但是,基于Visual Studio的使用经验,就希望尝试一种更友好的,更方便管理项目的IDE,分别尝试了PyCharm和Ec ...

  9. Windows下nginx下安装amqp

    1.复制php_amqp.dll 到php/ext/ 2.复制rabbitmq.4.dll 到php/3.复制rabbitmq.4.dll 到windows/system32/ (如32位) ,64位 ...

  10. IDE 设备(磁盘/CD-ROM)配置不正确。“ide1:1”上具有一个 IDE 从设备,但没有主设备。此配置在虚拟机中无法正常运行。请使用配置编辑器将磁盘/CD-ROM 从“ide1:1”移到“ide1:0”。

    开启vmware报这个错: IDE 设备(磁盘/CD-ROM)配置不正确.“ide1:1”上具有一个 IDE 从设备,但没有主设备.此配置在虚拟机中无法正常运行.请使用配置编辑器将磁盘/CD-ROM ...