Title: hdoj 4336 card collector
Question: Collect the cards to win the grand prize, the probability of each card, and the number of cards. Then, ask you and your expected number of cards to be bought.
Analysis: a maximum of 20 cards are compressed to indicate whether a card is taken.
For example, if there is a status of 10010, it indicates that the expected status is 2nd 3 5.
We ask for it. We can first get the expectations of 10011, and then multiply the probability that each bit does not get the total expectation. Except that the total probability is the current expectation,
Not very familiar. // a little anxious about mathematics IQ
AC code:
# Include <cstdio> # include <algorithm> # include <cstring> # include <string> # include <iostream> # include <vector> using namespace STD; const int INF = 0x3f3f3f3f; const int n = 22; double DP [1 <n], p [N]; // DP [st] indicates the expected int main () {int N; while (~ Scanf ("% d", & N) {double sum = 0; For (INT I = 0; I <n; I ++) scanf ("% lf ", & P [I]); DP [(1 <n)-1] = 0; For (INT ST = (1 <n)-2; ST> = 0; st --) {double TT = 0; For (INT I = 0; I <n; I ++) {If (! (St & (1 <I) DP [st] + = (DP [st | (1 <I)]) * P [I], tt + = P [I];} DP [st]/= tt;} printf ("%. 5lf \ n ", DP [0]);} return 0 ;}
Hdoj 4336 card collector [probability DP]