HDU 4336 card collector (expected)

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4336


There are N types of cards. Each bag of snacks contains at most one card, which gives the probability of each card in a bag of snacks. Ask how many bags of snacks can be collected to all the cards on average.


Status is compressed. There are 1 <n-1 statuses, and DP [sta] indicates the average number of snacks bought from the current status to the target status, it is known that the final state DP [1 <n-1] = 0, DP [sta] can be obtained from the following State:

There is no card in this bag of snacks, the probability is P (the probability that there is no card), the status is transferred to sta;

This bag of snacks contains card J, but he already owns this card, probably a [J], and the status is changed to sta;

This bag of snacks contains card J, which has never been used before. The probability is a [J] and the status is transferred to sta | (1 <j)

Push back.


# Include <stdio. h> # include <iostream> # include <map> # include <set> # include <list> # include <stack> # include <vector> # include <math. h> # include <string. h> # include <queue> # include <string> # include <stdlib. h> # include <algorithm> // # define ll _ int64 # define ll long # define EPS 1e-9 # define PI ACOs (-1.0) using namespace STD; const int INF = 0x3f3f3f; const int maxn = 4010; double DP [1100000]; Double A [22]; In T Main () {int N; while (~ Scanf ("% d", & N) {double T = 0; For (INT I = 0; I <n; I ++) {scanf ("% lf ", & A [I]); t + = A [I];} t = 1-T; memset (DP, 0, sizeof (DP )); int M = (1 <n)-1; DP [m] = 0; For (INT sta = m-1; STA> = 0; sta --) {double S1 = 0, s2 = 0; For (Int J = 0; j <n; j ++) {If (! (STA & (1 <j) {S1 + = A [J] * DP [sta | (1 <j)];} elses2 + = A [J];} S1 + = 1; DP [sta] = S1/(1-s2-t);} printf ("%. 4lf \ n ", DP [0]);} return 0 ;}




HDU 4336 card collector (expected)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.