Click here to view the question Surface
General question:You have two types of capturing balls (\ (A \) and \ (B \) respectively). To capture \ (n \) Pokémon, the \ (I \) the probability that a Pokémon will be captured by the first ball is \ (s1_ I \), the probability of being captured by the second ball is \ (s2_ I \), and the expected number of pokémon under the optimal strategy.
\ (Wqs \) binary
This should be a classic question of \ (wqs \) (after all, yes\ (Wqs \) binary sets \ (wqs \) binary).
\ (Wqs \) binary sets \ (wqs \) binary
If you know \ (wqs \) binary, it is not difficult to think of \ (wqs \) binary cost \ (C1 \), indicating the price required for each use of the first ball, then \ (wqs \) is used to calculate a price \ (C2 \), which indicates the price required for each second ball. So it becomes \ (wqs \) binary set \ (wqs \) binary.
\ (DP \) Transfer
After \ (wqs \), it is \ (DP.
We can use \ (f_ I \) to representThe maximum expectation of the total number of pokémon found by the number \ (I \) PokémonAnd \ (gpolici \)The first method used to capture the number of balls, Represented by \ (g2_ I \)The second method used to capture the number of balls.
In fact, \ (DP \) is also quite simple. There are \ (4 \) cases:
- No capturing ball is used. \ (F_ I = F _ {I-1}, g1_ I = G1 _ {I-1}, g2_ I = G2 _ {I-1 }\).
- Use the first method to capture the ball. \ (F_ I = F _ {I-1} + s1_i-C1, g1_ I = G1 _ {I-1} + 1, g2_ I = G2 _ {I-1 }\)
- Use the second method to capture the ball. \ (F_ I = F _ {I-1} + s2_i-C2, g1_ I = G1 _ {I-1}, g2_ I = G2 _ {I-1} + 1 \)
- Use two types of capturing balls at the same time. \ (F_ I = F _ {I-1} + s1_ I + s2_i-C1-C2-s1_ I * s2_ I, g1_ I = G1 _ {I-1} + 1, g2_ I = G2 _ {I-1} + 1 \)
In this way, you can.
Code
# Include <bits/stdc ++. h> # define max (x, y) (x)> (y )? (X) :( y) # define min (x, y) (x) <(y )? (X) :( y) # define uint unsigned int # define ll long # define ull unsigned long # define swap (x, y) (x ^ = Y, y ^ = x, x ^ = y) # define ABS (x) <0? -(X) :( X) # define INF 1e9 # define Inc (x, y) (x + = (y)> = mod & (X-= mod) # define ten (x) <3) + (x) <1 )) # define n 100000 # define EPS 1e-12using namespace STD; int n, a, B; double S1 [n + 5], S2 [n + 5]; class class_wqs // wqs binary set wqs binary {PRIVATE: Double C1, C2, F [n + 5]; int G1 [n + 5], G2 [n + 5]; // use F [I] to indicate the maximum expectation of the total number of pokémon captured by the nth Pokémon, and use G1 [I] to indicate the number of balls captured by the first one, use G2 [I] to indicate the second number of balls to be captured. inline void check () // DP transfer {for (register int I = 1; I <= N; + + I) {f [I] = f [I-1], G1 [I] = G1 [I-1], G2 [I] = G2 [I-1]; // do not use catch ball if (F [I-1] + (S1 [I]-C1)-f [I]> EPS) f [I] = f [I-1] + (S1 [I]-C1), G1 [I] = G1 [I-1] + 1, g2 [I] = G2 [I-1]; // use the first Snap ball if (F [I-1] + (s2 [I]-C2)-f [I]> EPS) f [I] = f [I-1] + (s2 [I]-C2), G1 [I] = G1 [I-1], g2 [I] = G2 [I-1] + 1; // use the second capture ball if (F [I-1] + (S1 [I] + S2 [I]-C1-C2-s1 [I] * S2 [I]) -F [I]> EPS) f [I] = f [I-1] + (S1 [I] + S2 [I]-C1-C2-s1 [I] * S2 [I]), g1 [I] = G1 [I-1] + 1, G2 [I] = G2 [I-1] + 1; // use both capture balls} inline void Getres () // second-level binary, second-level C2 {register double L = 0.0, r = 1.0; For (C2 = (L + r)/2; R-l> EPS; c2 = (L + r)/2) {If (check (),! (G2 [N] ^ B) return; // find the qualified C2, and you can return G2 [N]> B? L = c2: r = c2; // If the selected item quantity is too large, update L to C2; otherwise, update R to C2} public: inline double getans () // second layer, Second Division C1 {register double L = 0.0, r = 1.0; For (C1 = (L + r)/2; R-l> EPS; c1 = (L + r)/2) {If (getres (),! (G1 [N] ^ A) break; // find the qualified C1, then you can break G1 [N]>? L = C1: r = C1; // If the selected item quantity is too large, update L to C1, otherwise, update R to C1} return f [N] + A * C1 + B * C2; // return answer} wqs; int main () {register int I; scanf ("% d", & N, & A, & B); for (I = 1; I <= N; ++ I) scanf ("% lf", & S1 [I]); for (I = 1; I <= N; ++ I) scanf ("% lf ", & S2 [I]); Return printf ("%. 10lf \ n ", wqs. getans (), 0 ;}
[Cf739e] Gosha is hunting (wqs dual set wqs dual)