Question: there are two people A and B, and n questions. Each question has A corresponding score. The probability of B answering A question is 0.5, the probability that A will not lose to B is not less than the Gini score P wants
Idea: DP, dp [I] [j] indicates the probability that B answers the question I before and after the score is j. Then, the probability of B is used to calculate the Gini score of.
# Include
# Include
# Include
# Include using namespace std; const int MAXN = 40010; int a [MAXN], n; double P, dp [50] [MAXN]; int main () {int t; scanf ("% d", & t); while (t --) {scanf ("% d % lf", & n, & P); int sum = 0; for (int I = 0; I <n; I ++) {scanf ("% d", & a [I]); sum + = a [I];} memset (dp, 0, sizeof (dp); dp [0] [0] = 1; for (int I = 0; I <n; I ++) for (int j = 0; j <= sum-a [I]; j ++) if (dp [I] [j]> 0) {dp [I + 1] [j + a [I] + = dp [I] [j] * 0.5; dp [I + 1] [j] + = dp [I] [j] * 0.5;} int ans = 0; double cnt = 0; for (int I = 0; I <= sum; I ++) {cnt + = dp [n] [I]; if (cnt> = P) {ans = I; break ;}} printf ("% d \ n", ans);} return 0 ;}