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  — 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值