天天看点

ZOJ 3640 Help Me Escape (期望dp)

题意:

一只吸血鬼,有n条路给他走,每次他随机走一条路,每条路有个限制,如果当时这个吸血鬼的攻击力大于等于某个值,那么就会花费t天逃出去

否则花费1天的时间,并且攻击力增加,问他逃出去的期望

分析:

dp[i]:=攻击力为i逃出去的期望,逆序递推或者记忆化搜索都行

代码:

//
//  Created by TaoSama on 2015-10-09
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N =  + , INF = , MOD =  + ;

int n, f, c[];
double dp[N];
bool vis[N];

double get(int x) {
    return floor(( + sqrt()) /  * x * x);
}

double dfs(int f) {
    if(vis[f]) return dp[f];
    vis[f] = true;
    dp[f] = ;
    for(int i = ; i <= n; ++i) {
        if(f > c[i]) dp[f] += get(c[i]);
        else dp[f] +=  + dfs(f + c[i]);
    }
    dp[f] /= n;
    return dp[f];
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio();

    while(scanf("%d%d", &n, &f) == ) {
        for(int i = ; i <= n; ++i) scanf("%d", c + i);
        memset(vis, false, sizeof vis);
        printf("%.3f\n", dfs(f));
    }
    return ;
}