Gym 100338I TV show (dfs enumeration)

Source: Internet
Author: User
Tags cmath

Gym 100338I TV show (dfs enumeration)
Gym 100338I:

A person goes to a TV prize-winning Q & A program with an initial prize of 100 yuan. Each time he answers a question, the prize doubles and the reward is cleared. In addition, there is an insurance opportunity: If you spend C's prize, you can double the next question, and the wrong answer will not be cleared.
Now we will give you the probability of correct answers to each question, and find the best answer policy's bonus expectations.

Ideas:

Do not consider insurance opportunities first. The reward expectation for leaving after question j is:
100? 2j? Tianji = 1pi
In this case, we can enumerate the reward expectations for leaving the j-th question and maintain the maximum value (note that you can leave without answering a question, and expect it to be 100 ).

Now we have to consider the situation of insurance opportunities. If we use insurance before answering question j, we will split two situations. Question j is not correct. For example, answer question j: there are 200 yuan, c = 50, pj = 50, then split the answer to 300 yuan, not 150 yuan, then, 300 yuan and 150 yuan are treated as initial bonuses respectively. The calculation based on the above calculation method is the expectation of insurance before question j, and the maintenance maximum value is the answer.

Code:
/** @author FreeWifi_novicer* language : C++/C*/#include
  
   #include
   
    #include
    
     #include
     
      #include
      
       #include#include
       
        #include
        #include
         
          #include
          
           #include
           
            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 long lint;typedef long long ll;typedef long long LL;double a[55] ;int n , c ; double dfs( int cur , double e , bool have ){ if( cur >= n ) return e ; double tmp = max( e , a[cur] * dfs( cur + 1 , 2 * e , have ) ) ; double money = 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 ) ; return tmp ;}int main(){ freopen("tvshow.in","r",stdin); freopen("tvshow.out","w",stdout); //freopen( "input.txt" , "r" , stdin ) ; while( cin >> n >> c ){ for( int i = 0 ; i < n ; i++ ){ scanf( "%lf" , a+i ) ; a[i] /= 100 ; } double ans = dfs( 0 , 100.0 , true ) ; printf( "%.12f\n" , ans ) ; } return 0;}
           
          
         
       
      
     
    
   
  

Copyright statement: the blogger authorizes everyone to reprint everything :)

Related Article

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.