vc<vc<double>> dp(a + 1, vc<double>(b + 1, 0.00)); rep (i, n) { double pp = p[i]; double qq = q[i]; double pq = pp + qq - pp * qq; int na = a * i / n; int nb = b * i / n; int la = na - 50; int ra = na + 50; int lb = nb - 50; int rb = nb + 50; cmax(la, 0); cmax(lb, 0); cmin(ra, i + 1); cmin(rb, i + 1); for (int x = ra - 1; x >= la; x--) { for (int y = rb - 1; y >= lb; y--) { if (x + 1 <= a && y + 0 <= b) cmax(dp[x + 1][y + 0], dp[x][y] + pp); if (x + 0 <= a && y + 1 <= b) cmax(dp[x + 0][y + 1], dp[x][y] + qq); if (x + 1 <= a && y + 1 <= b) cmax(dp[x + 1][y + 1], dp[x][y] + pq); } } }