* 分析*:
这题主要是理解SG函数。
SG函数的原理核心是定义的mex运算。这个运算的数值规则,吻合了必败态只能转移到必胜态,而必胜态必然可以找到一种方法转移到必败态的博弈规则。
这样我们就可以把一个游戏看成一个SG函数的运算了。如果一个游戏是由多个游戏组合而来的,那么根据nim游戏的证明,这多个游戏的SG值异或起来就是母游戏的SG值。
本题中母游戏可以分解为两个子游戏,异或起来就可以。而初始必败态(sg = 0),就是(1 x n)的棋盘。
#include <iostream>
#include <set>
#include <cstring>
#include <cstdio>
#define pl(x) std::cout << #x << ": " << x << std::endl
#define pr(x) std::cout << #x << ": " << x
struct solve
{
int dp[222][222];
int n, m;
void init() {
memset(dp, -1, sizeof(dp));
}
void input() {
init();
//while (std::cin >> n >> m) {
while (~scanf("%d%d", &n, &m)) {
puts(run(n, m) ? "WIN" : "LOSE");
}
}
int run(int x, int y) {
if (dp[x][y] != -1) return dp[x][y];
std::set<int> S;
for (int i = 2; i <= x - 2; i++) S.insert(run(i, y) ^ run(x - i, y));
for (int i = 2; i <= y - 2; i++) S.insert(run(x, i) ^ run(x, y - i));
int cnt = 0;
while (S.count(cnt)) cnt++;
return dp[x][y] = cnt;
}
}ac;
int main()
{
ac.input();
return 0;
}