# 【CF739E】Gosha is Hunting-期望DP+WQS二分

#include <bits/stdc++.h>
using namespace std;
const double eps=1e-8;
int n,a,b,numa[2010],numb[2010];
double p[2010],q[2010],f[2010];

int solve(double x,double y)
{
f[0]=0.0,numa[0]=0,numb[0]=0;
for(int i=1;i<=n;i++)
{
f[i]=f[i-1];
numa[i]=numa[i-1];
numb[i]=numb[i-1];
if (f[i-1]+p[i]-x>f[i])
{
f[i]=f[i-1]+p[i]-x;
numa[i]=numa[i-1]+1;
numb[i]=numb[i-1];
}
if (f[i-1]+q[i]-y>f[i])
{
f[i]=f[i-1]+q[i]-y;
numa[i]=numa[i-1];
numb[i]=numb[i-1]+1;
}
if (f[i-1]+p[i]+q[i]-p[i]*q[i]-x-y>f[i])
{
f[i]=f[i-1]+p[i]+q[i]-p[i]*q[i]-x-y;
numa[i]=numa[i-1]+1;
numb[i]=numb[i-1]+1;
}
}
}

int main()
{
scanf("%d%d%d",&n,&a,&b);
for(int i=1;i<=n;i++)
scanf("%lf",&p[i]);
for(int i=1;i<=n;i++)
scanf("%lf",&q[i]);

double l1=0.0,r1=1.0,l2,r2;
while(r1-l1>eps)
{
double mid1=(l1+r1)/2.0;
l2=0.0,r2=1.0;
while(r2-l2>eps)
{
double mid2=(l2+r2)/2.0;
solve(mid1,mid2);
if (numb[n]>b) l2=mid2;
else r2=mid2;
}
solve(mid1,r2);
if (numa[n]>a) l1=mid1;
else r1=mid1;
}
solve(r1,r2);
printf("%.8lf",f[n]+r1*(double)a+r2*(double)b);

return 0;
}
posted @ 2018-07-03 19:34  Maxwei_wzj  阅读(117)  评论(0编辑  收藏  举报