acdream1421 TV Show (枚举)
http://acdream.info/problem?pid=1421
Andrew Stankevich Contest 22
TV ShowSpecial JudgeTime Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)
Problem Description Charlie is going to take part in one famous TV Show. The show is a single player game. Initially the player has 100 dollars. The player is asked n questions, one after another. If the player answers the question correctly, the sum he has is doubled. If the answer is incorrect, the player gets nothing and leaves the show. Before each question the player can choose to leave the show and take away the prize he already has. Also once in the game the player can buy insurance. Insurance costs c dollars which are subtracted from the sum the player has before the question. Insurance has the following effect: if the player answers the question correctly his prize is doubled as usually, if the player answers incorrectly the prize is not doubled, but the game continues. The player must have more than c dollars to buy insurance. Charlie’s friend Jerry works on TV so he managed to steal the topics of the questions Charlie will be asked. Therefore for each question i Charlie knows pi — the probability that he will answer this question correctly. Now Charlie would like to develop the optimal strategy to maximize his expected prize. Help him.
Input The first line of the input file contains two integer numbers n and c (1 ≤ n ≤ 50, 1 ≤ c ≤ 109). The second line contains n integer numbers ranging from 0 to 100 — the probabilities that Charlie will answer questions correctly, in percent.
Output Output one real number — the expected prize of Charlie if he follows the optimal strategy. Your answer must have relative or absolute error within 10-8 .
Sample Input2 100 50 50 2 50 50 50 2 50 60 0 Sample Output100 112.5 120 Hint The optimal strategy in the second example is to take insurance for the second question. In this case the expected prize is 1/2 × 0 + 1/2 × (1/2 × 150 + 1/2 × 300). In the third example it is better to leave the show after the first question, because there is no reason to try to answer the second one.
SourceAndrew Stankevich Contest 22
Manager |
题意:
有个人参加答题活动,初始有100块,答对一题翻倍,答错一题直接没钱滚蛋。他可以选择在任意时刻拿着现有的钱跑。已知各个题答对的概率,求最高的得钱期望。
还有一个特殊设定,就是他可以在某个时刻买一个保险,保险需要c元,买了的话下一题答错了也不会滚蛋,而是会保持原有钱数继续。
题解:
注意保险只能买一次,直接枚举就行!
(之前以为保险随便买,卧槽,就不会了)
代码:
1 //#pragma comment(linker, "/STACK:102400000,102400000") 2 #include<cstdio> 3 #include<cmath> 4 #include<iostream> 5 #include<cstring> 6 #include<algorithm> 7 #include<cmath> 8 #include<map> 9 #include<set> 10 #include<stack> 11 #include<queue> 12 using namespace std; 13 #define ll long long 14 #define usll unsigned ll 15 #define mz(array) memset(array, 0, sizeof(array)) 16 #define mf1(array) memset(array, -1, sizeof(array)) 17 #define minf(array) memset(array, 0x3f, sizeof(array)) 18 #define REP(i,n) for(i=0;i<(n);i++) 19 #define FOR(i,x,n) for(i=(x);i<=(n);i++) 20 #define RD(x) scanf("%d",&x) 21 #define RD2(x,y) scanf("%d%d",&x,&y) 22 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z) 23 #define WN(x) printf("%d\n",x); 24 #define RE freopen("D.in","r",stdin) 25 #define WE freopen("huzhi.txt","w",stdout) 26 #define mp make_pair 27 #define pb push_back 28 const double pi=acos(-1.0); 29 const double eps=1e-10; 30 31 const int maxn=55; 32 33 int n; 34 double c; 35 int a[maxn]; 36 37 inline double dfs(const int &x,const double &s,const bool bought) { 38 double t=s; 39 if(x>=n)return s; 40 t=max(t , a[x]/100.0*dfs(x+1 , 2*s , bought)); 41 if(s>=c && bought!=1)t=max(t , dfs(x+1 , (a[x]*2.0*(s-c) + (100-a[x])*(s-c))/100.0 , 1)); 42 return t; 43 } 44 45 double farm() { 46 return dfs(0,100.0,0); 47 } 48 49 int main() { 50 int i; 51 while(scanf("%d%lf",&n,&c)!=EOF) { 52 REP(i,n)RD(a[i]); 53 printf("%f\n",farm()); 54 } 55 }