天天看點

ACdream 1421 TV Show

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 p 

i — 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 ≤ 10 

9). 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 Input

2 100

50 50

2 50

50 50

2 50

60 0

Sample Output

100

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.

#include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>
#include<functional>
#include<algorithm>
using namespace std;
const int maxn = 20005;
int  n;
double a[maxn], c;

double dfs(int now, double s, int flag)
{
  if (now > n) return s;
  double sum = max(s, a[now] * dfs(now + 1, s * 2, flag)), res = 0;
  if (s > c && flag)
  {
    res += a[now] * dfs(now + 1, (s - c) * 2, 0);
    res += (1 - a[now]) * dfs(now + 1, s - c, 0);
  }
  return max(sum, res);
}

int main()
{
  while (~scanf("%d%lf", &n, &c))
  {
    for (int i = 1; i <= n; i++) 
      scanf("%lf", &a[i]), a[i] /= 100;
    printf("%.9lf\n", dfs(1, 100, 1));
  }
  return 0;
}