Dynamic Programming21 sections · 916 units
Open in Course

Codeforces 739E Gosha is Hunting - Problem Statement

Codeforces 739E

You have nn Pokemon, aa Poke Balls, and bb Ultra Balls. Pokemon ii is caught with probability pip_i by Poke Ball, uiu_i by Ultra Ball. You can use at most one of each ball type per Pokemon. Find the largest expected catches.

If you throw both balls at Pokemon ii, the catch probability is pi+uipiuip_i + u_i - p_i \cdot u_i (at least one succeeds). The constraint is two-dimensional: exactly aa Poke Balls AND exactly bb Ultra Balls. Standard DP is O(nab)O(n \cdot a \cdot b), which is O(n3)O(n^3). Too slow.