萌新刚学博弈论,WA on #7 求助
查看原帖
萌新刚学博弈论,WA on #7 求助
735763
_ChongYun_楼主2024/5/25 09:52
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
int sg[222][222];
bool vis[222][222];
vector<int> qwq;
int SG(int x,int y){
	if((x==2&&y==2)||(x==2&&y==3)||(x==3&&y==2)||(x==3&&y==3)) return 0;
	if(sg[x][y]>=0) return sg[x][y];
	qwq.clear();
	for(int i=2;i<x-1;i++) qwq.push_back(SG(i,y)^SG(x-i,y));
	for(int i=2;i<y-1;i++) qwq.push_back(SG(x,i)^SG(x,y-i));
	qwq.push_back(1145141919810);
	sort(qwq.begin(),qwq.end());
	unique(qwq.begin(),qwq.end());
	int qwp=-1;
	for(int i=0;i<qwq.size();i++){
		if(qwq[i]!=qwp+1){
			sg[x][y]=qwp+1;
			return qwp+1;
		}
		qwp=qwq[i];
	}
	return 0;
}
signed main(){
	while(cin>>n>>m){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				sg[i][j]=-1145141919810;
			}
		}
		sg[2][2]=sg[2][3]=sg[3][2]=sg[3][3]=0;
		if(SG(n,m)) printf("WIN\n");
		else printf("LOSE\n");
	}
	return 0;
}
2024/5/25 09:52
加载中...