poj 2960,hdu 1536 S-NIM 博弈

简介:

    同样的题目,又不会写了,还是没有完全理解博弈的内涵,又看了遍论文。

    明天一定要搞懂

    目前最新的想法是每个sg函数值代表的是到达必败态的方法,如果2个必胜方法一样,那么为输,否则为胜。明天再好好看看


/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int s[101];
int k;
int sg[10005];
int get_sg(int x)
{
    if(~sg[x])return sg[x];
    int vis[101],i;
    memset(vis,0,sizeof(vis));
    for(i=0;i<k;i++)
    {
        if(s[i]>x)break;
        vis[get_sg(x-s[i])]=1;
    }
    for(i=0;vis[i];i++);
    return sg[x]=i;
}
int main()
{
    int i;
    while(~scanf("%d",&k)&&k)
    {
        memset(sg,-1,sizeof(sg));
        sg[0]=0;
        for(i=0;i<k;i++) scanf("%d",&s[i]);
        sort(s,s+k);
        int n,T,ans;
        scanf("%d",&T);
        while(T--)
        {
            ans=0;
            scanf("%d",&n);
            while(n--)
            {
                scanf("%d",&i);
                ans^=get_sg(i);
            }
            putchar(ans?'W':'L');
        }
        puts("");
    }
}


目录
相关文章
|
8月前
poj 1185 炮兵阵地 (状态压缩dp)
如果你是刚刚开始做状态压缩dp,我建议你先看看 poj 3254 Corn Fields 这是一道比这一题更简单,更容易入门的题目。 还有在代码中我用了一个很巧妙的方法求一个数二进制数中1的个数 具体请看我博客中 x& (x - 1)==0 这篇文章 链接 。
23 1
|
人工智能 决策智能
博弈论(NIM游戏——取石子)相关的题目
博弈论(NIM游戏——取石子)相关的题目
127 0
HDU5088 Revenge of Nim II(高斯消元求自由元个数 Nim博弈)
HDU5088 Revenge of Nim II(高斯消元求自由元个数 Nim博弈)
73 0
|
网络架构
POJ-1005,I Think I Need a Houseboat(数学题)
POJ-1005,I Think I Need a Houseboat(数学题)
HDU-2897,邂逅明下(巴什博弈)
HDU-2897,邂逅明下(巴什博弈)