Codeforces Gym 100338I TV Show 傻逼DFS,傻逼题

Problem I. TV Show
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88926#problem/I

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 Input

2 100
50 50

Sample Output

100

HINT

题意

你正在参加答题活动,每次你可以选择答还是不答,如果你答对了,奖金翻倍,如果答错了,1分钱也拿不到并且滚蛋

答题中你可以买一个保险,使得自己下次就算答错了,也不会有惩罚

题解

我真是日了,我想了一个小时这个傻逼DFS,比赛中没AC

我回去写了N份这道题的不同姿势,全部WA

结果告诉我,是我读题读错了,是我读题读错了,我真是……

这傻逼题

傻逼DFS就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff;   //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//**************************************************************************************

double p[120];
double ans=0;
double dp[100][100];
int n,c;
void dfs(int t,int x,int y,double num,double pp,int k)
{k=0;//谁TM告诉我保险如果没用掉,下回合可以接着用的?

    if(t==x)
    {
        dp[x][y]+=num*pp;
        ans = max(dp[x][y],ans);
        return;
    }
    else if(k==1)
    {
        dfs(t+1,x,y,num*2,pp*p[t],1);
        dfs(t+1,x,y,num,pp*(1-p[t]),0);
    }
    else if(t==y&&num>=c)
    {
        dfs(t+1,x,y,(num-c)*2,pp*p[t],1);
        dfs(t+1,x,y,(num-c),pp*(1-p[t]),0);
    }
    else
        dfs(t+1,x,y,num*2,pp*p[t],0);
}
int main()
{
    freopen("tvshow.in","r",stdin);
    freopen("tvshow.out","w",stdout);
    n=read(),c=read();
    for(int i=1;i<=n;i++)
    {
        cin>>p[i];
        p[i]/=100;
    }
    for(int j=1;j<=n+1;j++)
    {
        for(int k=0;k<j;k++)
        {
            dfs(1,j,k,100.0,1.0,0);
        }
    }
    printf("%.10lf
",ans);
}
原文地址:https://www.cnblogs.com/qscqesze/p/4749437.html