#include <cstring>
#include <cstdio>
#include <set>
#define MAX_N 200+16
using namespace std;
int sg[MAX_N][MAX_N];
int grundy(int w,int h)
{
int i;
if(sg[w][h]!=-1)
return sg[w][h];
set<int>s;
for(i=2;w-i>=2;i++)
s.insert(grundy(i,h)^grundy(w-i,h));
for(i=2;h-i>=2;i++)
s.insert(grundy(w,i)^grundy(w,h-i));
int res=0;
while(s.count(res))
res++;
return sg[w][h]=res;
}
int main()
{
int w,h;
memset(sg,-1,sizeof(sg));
while(~scanf("%d%d",&w,&h))
{
if(w<2||h<2)
break;
if(grundy(w,h))
printf("WIN\n");
else
printf("LOSE\n");
}
return 0;
}
poj 2311 (博弈,分解为子问题)
最新推荐文章于 2018-11-30 22:55:19 发布