void SolveSmall() { ans = 0; var ids = new int[k]; double[,] dp = new double[20, 40]; for (int mask = 0; mask < 1 << n; ++mask) { if (BitUtils.CountOnes(mask) != k) { continue; } int z = 0; for (int i = 0; i < n; i++) { if (BitUtils.BitInMask(mask, i)) { ids[z++] = i; } } dp[0, 0] = 1; for (int i = 1; i <= k; i++) { for (int j = 0; j <= i; ++j) { dp[i, j] = p[ids[i - 1]] * (j == 0 ? 0 : dp[i - 1, j - 1]) + (1 - p[ids[i - 1]]) * dp[i - 1, j]; } } ans = Math.Max(ans, dp[k, k / 2]); } }