poj 2311 Cutting Game 博弈论

思路:求SG函数!!

代码如下:

 

 1 #include<iostream>

 2 #include<cstdio>

 3 #include<cmath>

 4 #include<cstring>

 5 using namespace std;

 6 int sg[202][202];

 7 int getsg(int m,int n)

 8 {

 9     if(sg[m][n]!=-1) return sg[m][n];

10     bool vis[200];

11     memset(vis,0,sizeof(vis));

12     for(int i=2;i<=m/2;i++) vis[getsg(i,n)^getsg(m-i,n)]=1;

13     for(int i=2;i<=n/2;i++) vis[getsg(m,i)^getsg(m,n-i)]=1;

14     int i=0;

15     while(vis[i]) i++;

16     return sg[m][n]=i;

17 }

18 int main()

19 {

20     memset(sg,-1,sizeof(sg));

21     int m,n;

22     while(cin>>m>>n) puts(getsg(m,n)?"WIN":"LOSE");

23     return 0;

24 }
View Code

 

 

 

你可能感兴趣的:(game)