Topic Portal (internal title 38)
Input Format
Each input file contains several test cases. Players should be addressed to the end of the file (the EOF $ $)
each comprising a set of data lines $ 3 $.
The first line contains three $ 1 $ positive integers $ n, a, b $, $ n-expressed cat $, $ gyz $ $ A $ packages have simply face pack and $ b $ curd.
The first line contains $ 2 $ $ n $ reserved $ 3 $ decimal places real number $ p_1, p_2 ... p_n $, $ p_i $ represents the $ i like to simply face the probability of $ cats.
The first line contains $ 3 $ $ n $ reserved $ 3 $ decimal places real number $ q_1, q_2 ... q_n $, $ q_i $ $ i represents the probability of $ cats like tofu.
Output Format
Each test case output a line representing the number of cats caught expect the optimal strategy. $ 3 $-bit output retained after the decimal point.
Sample
Sample input:
3 2 2
1.000 0.000 0.500
0.000 1.000 0.500
4 1 3
0.100 0.500 0.500 0.600
0.100 0.500 0.900 0.400
3 2 0
0.412 0.198 0.599
0.612 0.987 0.443
Sample output:
2.75000
2.16000
1.01100
Data range and tips
$ T $ represents the number of test data sets, $ \ sum n $ denotes an input file $ n $ of all data and.
$ 100 \% $ data, $ T \ leqslant 10, \ sum n $ $ does not exceed $ 100,000.
$ 100 \% $ data, $ 0 \ leqslant a \ leqslant n, 0 \ leqslant b \ leqslant n $.
Each test point $ n, T $ range in the table below.
answer
The original title is $ codeforces 794E $, This question i increase the scope of data increased the difficulty (Official explanations of the original title $ \ Theta (n ^ 2 \ log n) $ time complexity).
For convenience, hereinafter referred to simply face hot strip ......
For this question, we expect the number of probability caught the cat is the cat likes.
So for a cat, it is divided into four cases:
$ \ Alpha. $ Is not fed, contributions to $ 0 $.
$ \ Beta. $ Hot strip feeding, contributions to $ p_i $.
$ \ Gamma. $ Fed tofu, contributions to $ q_i $.
$ \ Delta. $ Are fed, contributions to $ p_i + q_i-p_i \ times q_i $ (minus the note can be interpreted as the probability of all like).
Consider first $ \ Theta (n \ times a \ times b) $ a $ DP $.
Defined $ dp [i] [j] [k] $ I $ denotes the first cat $, $ J $ use a hot item, a maximum value of $ k $ of curd.
So is the state transition equation:
$ DP [I] [J] [K] = \ max (DP [. 1-I] [J] [K], DP [. 1-I] [J-. 1] [. 1-K ] + p_i + q_i-p_i \ times q_i, dp [i-1] [j-1] [k] + p_i, dp [i-1] [j] [k-1] q_i) $
Note that the space problem, be careful not to $ MLE $, otherwise you $ TM $ double the $ LE $.
I do not know if anyone still remember this question [BZOJ2654]: tree (Kruskal + WQS half) , and of course I am talking about is a positive solution, that is, $ WQS $ (Love Potion) half.
那么这道题我们也可以这样考虑,先将所有的辣条都加一个额外的代价,然后用花费的辣条跟总辣条数做比较;豆干同理。
时间复杂度:$\Theta(n\log^2n)$。
期望得分:$100$分。
实际得分:$100$分。
代码时刻
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
double p[100001],q[100001];
double dp[100001],fp[100001],fq[100001];
void calc(double x,double y)
{
for(int i=1;i<=n;i++)
{
dp[i]=dp[i-1];
fp[i]=fp[i-1];
fq[i]=fq[i-1];
if(dp[i-1]+p[i]>dp[i]+x)
{
dp[i]=dp[i-1]+p[i]-x;
fp[i]=fp[i-1]+1;
fq[i]=fq[i-1];
}
if(dp[i-1]+q[i]>dp[i]+y)
{
dp[i]=dp[i-1]+q[i]-y;
fp[i]=fp[i-1];
fq[i]=fq[i-1]+1;
}
if(dp[i-1]+p[i]+q[i]-p[i]*q[i]>dp[i]+x+y)
{
dp[i]=dp[i-1]+p[i]+q[i]-p[i]*q[i]-x-y;
fp[i]=fp[i-1]+1;
fq[i]=fq[i-1]+1;
}
}
}
double dichotomize2(double mid1)
{
double lft=0,rht=1;
while(rht-lft>1e-8)
{
double mid2=(lft+rht)/2;
calc(mid1,mid2);
if(fq[n]>b)lft=mid2;
else rht=mid2;
}
return rht;
}
pair<double,double> dichotomize1()
{
double lft=0,rht=1;
while(rht-lft>1e-8)
{
double mid=(lft+rht)/2;
calc(mid,dichotomize2(mid));
if(fp[n]>a)lft=mid;
else rht=mid;
}
double flag=dichotomize2(rht);
calc(rht,flag);
return make_pair(rht,flag);
}
int main()
{
while(~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]);
pair<double,double> flag=dichotomize1();
printf("%.3lf\n",dp[n]+a*flag.first+b*flag.second);
}
return 0;
}
rp++