HDU 4597 Play Game

Posted LJZ_C

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 4597 Play Game相关的知识,希望对你有一定的参考价值。

题目链接

有两个双端队列每次每人可以从任意一堆的头或尾取值,两人均采取最优策略,问先手的最后得分

很简单的博弈

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int inf = 1000000000;
int T, N, A[25], B[25], f[25][25][25][25];
int DP(int a, int b, int c, int d) {
    int turn = N - (b - a + 1) + N - (d - c + 1);
    if(turn == (N << 1)) return 0;
    int & res = f[a][b][c][d];
    if(res != -1) return res;
    if(turn & 1) {
        res = inf;
        if(a <= b) res = min(res, DP(a + 1, b, c, d));
        if(a <= b) res = min(res, DP(a, b - 1, c, d));
        if(c <= d) res = min(res, DP(a, b, c + 1, d));
        if(c <= d) res = min(res, DP(a, b, c, d - 1));
    }
    else {
        res = 0;
        if(a <= b) res = max(res, DP(a + 1, b, c, d) + A[a]);
        if(a <= b) res = max(res, DP(a, b - 1, c, d) + A[b]);
        if(c <= d) res = max(res, DP(a, b, c + 1, d) + B[c]);
        if(c <= d) res = max(res, DP(a, b, c, d - 1) + B[d]);
    }
    return res;
}
int main() {
    scanf("%d", &T);
    for(int kase = 1; kase <= T; kase++) {
        scanf("%d", &N);
        for(int i = 1; i <= N; i++) {
            scanf("%d", &A[i]);
        }
        for(int i = 1; i <= N; i++) {
            scanf("%d", &B[i]);
        }
        memset(f, -1, sizeof(f));
        printf("%d\n", DP(1, N, 1, N));
    }
    return 0;
}

以上是关于HDU 4597 Play Game的主要内容,如果未能解决你的问题,请参考以下文章

HDU 4597 Play Game

hdu 4597 Play Game(记忆化搜索)

[HDU 4597] Play Game

Play Game (博弈DP)

HDU 1564 Play a game && HDU 2147 kiki's game

题解报告:hdu 1564 Play a game(找规律博弈)