Gym 100338I TV Show (Dfs enumeration)

Source: Internet
Author: User

Gym 100338I Test Instructions:

A person to participate in the TV award-winning program, the initial bonus of 100 yuan, each answer a question bonus double, answer the wrong bonus clear zero. In addition, there is an insurance opportunity: to spend C's bonus, the next question can answer the bonus double, the wrong bonus is not clear zero.
Now give you the probability to answer each question, and seek the best strategy of bonus expectations.

Ideas:

Do not consider an insurance opportunity first. The bonus expectation to answer the question of the exit after J is:
-? 2 J ? ∏ J i = 1 p i
Then we enumerate the answer to the question of the bonus expected to leave after the J, maintain its maximum value (note can also not answer a question straight away, the expectation is 100).

Then we are now to consider the situation of insurance opportunities, we enumerate the answer to the first question of the insurance, then we will split two kinds of cases, the first question of the J answer is not correct, for example, the answer to the J before 200 yuan, C = 50, and PJ = 300, then split the right after the wrong $150, And then put 300 yuan and 150 yuan respectively as the initial bonus, according to the calculation method previously said to add up is the first question before the use of insurance expectations, the maintenance of the maximum value is the answer.

Code:
/** @author freewifi_novicer* language:c++/c*/#include <cstdio>#include <iostream>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <string>#include <map>#include <set>#include <vector>#include <queue>using namespace STD;#define CLR (x, y) memset (x,y,sizeof (x) )#define CLS (x) memset (x,0,sizeof (x) )#define MP Make_pair#define PB Push_backtypedef Long LongLinttypedef Long Longlltypedef Long LongLL;Doublea[ -] ;intn, C;DoubleDfsintCur,DoubleEBOOLHave) {if(cur >= N)returnEDoubleTMP = MAX (e, a[cur] * DFS (cur +1,2* e, have));DoubleMoney =0;if(E > C && have) {Money + = (1.0-a[cur]) * DFS (cur +1, E-c,false) ; Money + = (a[cur]) * DFS (cur +1,2* (E-C),false) ; } TMP = MAX (TMP, money);returnTMP;}intMain () {Freopen ("Tvshow.in","R", stdin); Freopen ("Tvshow.out","W", stdout);//freopen ("Input.txt", "R", stdin);     while(Cin>> n >> c) { for(inti =0; I < n; i++) {scanf("%LF", a+i); A[i]/= -; }DoubleAns = DFS (0,100.0,true) ;printf("%.12f\n", ans); }return 0;}

Copyright notice: Bo Master said authorized all reproduced:)

Gym 100338I TV Show (Dfs enumeration)

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.