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可 ...
随机推荐
- tab$被删除恢复指南
by 蔡建良 2019-2-25 经过长时间摸索,参考网上各类文章.今天终于让我成功恢复了oracle的sys.tab$表,并成功打开了数据库. 将此过程记录下来,与大家共享.如有疑问可联系我QQ: ...
- idea中使用MyBatis Generator
1.新建maven项目 2.新建Generator配置文件 generator_config.xml <?xml version="1.0" encoding="U ...
- Chrome 58.xxx,iisExpress 创建的SSL网站显示安全正式错误Error:net::ERR_CERT_COMMON_NAME_INVALID
https://www.reddit.com/r/sysadmin/comments/677hep/chrome_58_not_supporting_self_signed_certificates/ ...
- mysql------Windows7 64bit安装教程------下载mysql
.1.进入官网的下载位置,https://dev.mysql.com/downloads/installer/: 2.选择“Windows”; 3.点击"MySQL Installer&qu ...
- 自定义panel实现,并实现item更改和移除动画。
原地址:https://www.cnblogs.com/yk250/p/10043694.html 无图无真相: 1,重写panel类(模拟实现一个竖直方向排列的panel,相当于默认的StackP ...
- tomcat安装启动之后localhost:8080页面进不去,提示错误500
具体的错误展示页面如下: 首先,需要考虑到是不是安装的tomcat版本和自己安装的jdk的版本一致,如果不一致,建议将tomcat换成和jdk一致或者高于jdk版本的tomcat版本.(比如安装的jd ...
- 对struts2一些理解
1.strust2框架是什么?为解决什么问题出现? Struts2是在WebWork+xwork基础发展而来的. 2. strust2的优缺点优点: 支持Ajax 支持Ognl标签 提供了强大的拦截器 ...
- consul的安装与使用
consul官网下载地址 https://www.consul.io/downloads.html 下载后解压 在bat文件中增加如下内容,就可以双击启动了 start consul agent -d ...
- HttpClient 302重定向
CloseableHttpClient是线程安全的,单个实例可用于处理多个HTTP请求,Http Client会自动处理所有的重定向,关闭自动重定向需要设定disableAutomaticRetrie ...
- 05 JS基础DOM
JS的window对象定时器: window下一些方法: <script> 弹出 window.alert('hello') 返回布尔值 var ret = window.confirm( ...