hdu3649(取石子博弈+dp)

#include <cstdio>
int f[10][10][10];
bool vis[10][10][10];

int dp(int a, int b, int c) {
    if (vis[a][b][c])
        return f[a][b][c];
    int& ans = f[a][b][c];
    vis[a][b][c] = true;
    for (int i = 0; i < b; ++i)
        if (!dp(a, i, c))
            return ans = 1;
    for (int i = 0; i < c; ++i)
        if (!dp(a, b, i))
            return ans = 1;
    if (a && !dp(a - 1, b, c))
        return ans = 1;
    return ans = 0;
}

int main() {
    for (int i = 0; i < 10; ++i)
        for (int j = 0; j < 10; ++j) {
            vis[0][i][j] = true;
            f[0][i][j] = 1;
        }
    int n;
    while(scanf("%d",&n)==1) {
        int a,b,c,d;
        int aa,bb,cc,dd;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        scanf("%d%d%d%d",&aa,&bb,&cc,&dd);
        a=aa-a-1;
        b=bb-b-1;
        c=cc-c-1;
        int ans = dp(a, b, c);
        if(ans==1)
            printf("%s\n",n==0?"Red":"Black");
        else
            printf("%s\n",n==1?"Red":"Black");
    }
    return 0;
}

 

posted @ 2013-10-08 19:36  baoff  阅读(207)  评论(0编辑  收藏  举报