设$f[i][j][k]$表示前$i$个物品买了$j$个,消耗$k$个钻石,最少花多少钱,可以通过简单的DP求出。

枚举拥有的钻石数以及最多能购买的物品数的下界,那么钱数的下界是定值。

将$n$个箱子折半搜索,按钻石数分组并排序,枚举左半边每种方案,在右半边双指针求出总概率即可。

时间复杂度$O(nm2^{\frac{n}{2}}+nm^2)$。

#include<cstdio>
#include<algorithm>
const int N=33,inf=~0U>>2;
int T,n,m,lim,i,j,k,f[N][N][N],ca[N],cb[N];double p[N],ans;
struct P{int x;double p;P(){}P(int _x,double _p){x=_x,p=_p;}}a[N],A[N][33000],B[N][33000];
struct E{int c,d;}b[N];
inline bool cmp(const P&a,const P&b){return a.x<b.x;}
inline void up(int&a,int b){if(a>b)a=b;}
void dfsl(int x,int y,int z,double p){
if(x==lim){
A[y][++ca[y]]=P(z,p);
return;
}
dfsl(x+1,y,z+a[x].x,p*a[x].p);
dfsl(x+1,y+1,z,p*(1.0-a[x].p));
}
void dfsr(int x,int y,int z,double p){
if(x==n){
B[y][++cb[y]]=P(z,p);
return;
}
dfsr(x+1,y,z+a[x].x,p*a[x].p);
dfsr(x+1,y+1,z,p*(1.0-a[x].p));
}
inline double cal(int x,int y,int z){
if(z>=inf)return 0;
int n=ca[x],m=cb[y],i;double p=0,ret=0;
if(!n||!m)return 0;
for(i=1;i<=n;i++){
while(m&&A[x][i].x+B[y][m].x>=z)p+=B[y][m--].p;
ret+=A[x][i].p*p;
}
return ret;
}
int main(){
for(scanf("%d",&T);T--;printf("%.4f\n",ans)){
scanf("%d%d",&n,&m);lim=n/2;
for(i=0;i<n;i++)scanf("%d%lf",&a[i].x,&a[i].p),a[i].p*=0.01;
for(i=1;i<=m;i++)scanf("%d%d",&b[i].c,&b[i].d);
for(i=0;i<=m;i++)for(j=0;j<=m;j++)for(k=0;k<=n;k++)f[i][j][k]=inf;
f[0][0][0]=0;
for(i=1;i<=m;i++)for(j=0;j<=m;j++)for(k=0;k<=n;k++)if(f[i-1][j][k]<inf){
up(f[i][j][k],f[i-1][j][k]);
if(k+b[i].d<=n)up(f[i][j+1][k+b[i].d],f[i-1][j][k]+b[i].c);
}
for(j=0;j<=m;j++)for(k=1;k<=n;k++)up(f[m][j][k],f[m][j][k-1]);
for(i=0;i<=n;i++)ca[i]=cb[i]=0;
dfsl(0,0,0,1);
dfsr(lim,0,0,1);
for(i=0;i<=n;i++){
if(ca[i]>1)std::sort(A[i]+1,A[i]+ca[i]+1,cmp);
if(cb[i]>1)std::sort(B[i]+1,B[i]+cb[i]+1,cmp);
}
ans=p[m+1]=0;
for(i=0;i<=n;i++)for(j=m;j;j--){
p[j]=0;
for(k=0;k<=lim&&k<=i;k++)p[j]+=cal(k,i-k,f[m][j][i]);
ans+=(p[j]-p[j+1])*j;
}
}
return 0;
}

  

BZOJ4374 : Little Elephant and Boxes的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. Fedora 24 Gnome Boxes 无法ping通网络

    安装Fedora 24在试用虚拟机时发现无法ping通外网. 我傻傻地以为是软件问题. 问题描述: 尝试ping程序来测试网络连通性: (我之前也是ping百度,后来在为了少打字百度了一些比较短的域名 ...

  3. CF 204B Little Elephant and Cards

    题目链接: 传送门 Little Elephant and Cards time limit per test:2 second     memory limit per test:256 megab ...

  4. Problem B Boxes in a Line

     省赛B题....手写链表..其实很简单的.... 比赛时太急了,各种手残....没搞出来....要不然就有金了...注:对相邻的元素需要特判..... Problem B Boxes in a Li ...

  5. Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s

    C. Inna and Candy Boxes   Inna loves sweets very much. She has n closed present boxes lines up in a ...

  6. boxes

    boxes [英][bɒksɪz][美][bɑ:ksɪz] n.盒( box的名词复数 ); 一盒; 电视; 小亭; v.把…装入盒[箱,匣]中( box的第三人称单数 ); 拳击;   以上结果来自 ...

  7. Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)

    B. Candy Boxes Problem's Link:   http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...

  8. UVa 103 - Stacking Boxes(dp求解)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  9. [CareerCup] 9.10 Stack Boxes 垒箱子问题

    9.10 You have a stack of n boxes, with widths w., heights hir and depths drThe boxes cannot be rotat ...

随机推荐

  1. ubuntu 的 apt-get update 出现404错误时,或者添加ppa失败时,ubuntu 版本也 end of life 了的解决方案

    xmodulo.com/how-to-fix-apt-get-update-error-on-ubuntu.html 如果是依赖没找到,可以用 sudo apt-get install -f 先补齐依 ...

  2. nginx常见异常分析

    1.nginx不转发消息头header问题 proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_ ...

  3. [bzoj3123][洛谷P3302] [SDOI2013]森林(树上主席树+启发式合并)

    传送门 突然发现好像没有那么难……https://blog.csdn.net/stone41123/article/details/78167288 首先有两个操作,一个查询,一个连接 查询的话,直接 ...

  4. 【一通百通】c/php的printf总结

    程序语言都是触类旁通的,讲人话就是[一通百通].so今天说说工作中常用的printf的用法吧. 1.先说说PHP printf()函数: printf()函数的调用格式为: printf(" ...

  5. ANN算法总结

    kd-tree kd-tree works poorly in high dimensions (k<30) 自己实验的时候差不多20到30左右吧,超过之后,就真的很慢了 faiss suppo ...

  6. JS排序算法之快速排序

    const Arr = [85, 24, 63, 45, 17, 31, 96, 50]; function quickSort(arr) { 80 if (arr.length <= 1) { ...

  7. Numpy中stack(),hstack(),vstack()函数详解

    一`.stack 按指定维度堆叠数组.      stack(a, b) 维度计算 axis=0: 2*m*n axis=1:  m*2*n axis=-1: m*n*2 a = np.arange( ...

  8. Array数组内函数

      concat() 功能:合并数组,并且生成新数组.对原数组没有改变. 不传参数的时候,相当于生成新数组. 格式:数组.concat(数据...数组); 返回值:生成的新数组 代码示例: //.co ...

  9. 关于ie7下display:inline-block;不支持的解决方案。

    摘要: 声明:此文章为转载(点击查看原文),如有侵权24小时内删除.联系QQ:1522025433. 今天码的时候遇到这个问题了. 如果本身是内联元素的,把它的display属性设置设置为inline ...

  10. 国内最火5款Java微服务开源项目

    目录 1.pig 2.zheng 3.Cloud-Platform 4.SpringBlade 5.Guns 1.pig 开源地址:https://gitee.com/log4j/pig 基于Spri ...