HDU 5602 Black Jack(博弈dp)

题意:

21,[1,10],,[1,9]1/13,104/13
A,B2,A,,B,,
A,0.5YES,NO

分析:

f[A][a][b]:=Aa,Bb,A
f[B][a][b]:=Aa,Bb,B
A使,B使

代码:

//
//  Created by TaoSama on 2015-12-26
//  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 = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

double f[2][32][32];
bool vis[2][32][32];

int get(char c) {
    if(c == 'A') return 1;
    else if(isdigit(c)) return c - '0';
    return 10;
}

//1->losing prob
double dfs1(int a, int b) {
    if(b > 21) return 1;
    double &ret = f[1][a][b], tmp = 0;
    if(vis[1][a][b]) return ret;
    vis[1][a][b] = true;
    ret = a > b;
    for(int i = 1; i <= 9; ++i) tmp += dfs1(a, b + i);
    tmp += 4 * dfs1(a, b + 10);
    tmp /= 13;
    return ret = min(ret, tmp);
}

//0->winning prob
double dfs0(int a, int b) {
    if(a > 21) return 0;
    double &ret = f[0][a][b], tmp = 0;
    if(vis[0][a][b]) return ret;
    vis[0][a][b] = true;
    ret = dfs1(a, b);
    for(int i = 1; i <= 9; ++i) tmp += dfs0(a + i, b);
    tmp += 4 * dfs0(a + 10, b);
    tmp /= 13;
    return ret = max(ret, tmp);
}

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(0);

    int t; scanf("%d", &t);
    while(t--) {
        char s[5]; scanf("%s", s);
        double ans = dfs0(get(s[0]) + get(s[1]), get(s[2]) + get(s[3]));
//      printf("%.10f\n", ans);
        puts(ans > 0.5 ? "YES" : "NO");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值