https://www.zybuluo.com/ysner/note/1300794 Problem surface
There are now altogether \ (n\) Pokémon only. You have \ (a\) a baby ball and \ (b\) a super ball.
The probability that the baby ball catches the i\ Pokémon is \ (p_i\)? , the probability of the super ball catching is \ (u_i\).
You can't use more than one ball on the same Pokémon, but you can use both the baby ball and the Super ball (both of them).
Make a reasonable allocation of each ball to catch who, so that you catch the total number of Pokémon expected maximum, and output this value.
\ (n\leq2000\)
AnalyticalThere is a greedy approach to the lecture.
Sort by the Super ball capture probability first.
The last time to use the position of the super ball, the front is either \ (p+u\), or ( p\), the back is either (p\), or ( 0\).
So you can take a heap of greedy to choose to maximize expectations.
See this problem, bare \ (dp\) is three-dimensional.
Set \ (f[i][j][k]\) represents to the i\ of a baby, with a \ (j\) a baby ball,\ (k\) a super ball of expectations.
However \ (O (n^3) \) is not divided.
The following is an excerpt from the blog of the Troll Yyb
The discovery can be convex optimized, giving it two weights for one of the balls, indicating that each time it is used, it takes an extra amount of weight and no longer limits the number of uses.
Then ignore this limit, do \ (dp\), using the optimal solution to use the number of such balls and limit the number of continued two points.
Two-D can do this, complexity \ (O (nlog^2n) \).
How to say, the use of a two-strong weighted value instead of limiting the operation seems to appear more than once. For example [National training Team 2]tree I.
Knowledge learning is one thing, will not be flexible use is the same ...
There is also a detail, if you want to nest two points, the accuracy Requirements ((EPS) \) to double.
#include <iostream> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring > #include <algorithm> #include <set> #define LL Long long#define re register#define il inline#define db Double #define EPS 1e-8#define FP (i,a,b) for (re int i=a;i<=b;++i) #define FQ (I,A,B) for (re int i=a;i>=b;--i) using Nam Espace std;const int n=5e3+100;int n,ta,tb;db f[n],fa[n],fb[n];struct dat{db b;} T[n];il void Check (re db w1,re db W2) {fp (i,1,n) {f[i]=f[i-1];fa[i]=fa[i-1];fb[i]=fb[i-1]; if (F[i-1]+t[i].a-w1>f[i]) f[i]=f[i-1]+t[i].a-w1,fa[i]=fa[i-1]+1,fb[i]=fb[i-1]; if (F[i-1]+t[i].b-w2>f[i]) f[i]=f[i-1]+t[i].b-w2,fa[i]=fa[i-1],fb[i]=fb[i-1]+1; if (F[i-1]+t[i].a+t[i].b-t[i].a*t[i].b-w1-w2>f[i]) f[i]=f[i-1]+t[i].a+t[i].b-t[i].a*t[i].b-w1-w2,fa[i]=fa[i-1 ]+1,fb[i]=fb[i-1]+1; }}int Main () {Ios::sync_with_stdio (false); cin>>n>>ta>>tb; FP (i,1,n) cin>>t[i].a; FP (i,1,n) cin>>t[i].b; Re db l1=0,r1=1,mId1,l2,r2,mid2; while (L1+EPS<R1) {mid1= (L1+R1)/2; L2=0,r2=1; while (L2+EPS<R2) {mid2= (L2+R2)/2; Check (MID1,MID2); if (FB[N]>TB) L2=mid2;else R2=mid2; } check (MID1,R2); if (Fa[n]>ta) L1=mid1;else r1=mid1; } check (R1,R2); printf ("%.4lf\n", F[N]+R1*TA+R2*TB); return 0;}
[Cf739e]gosha is hunting