Click to open the topic link
/* Test instructions: Draw x in 1*n's grid, when there are three consecutive, win; then when the first person draws in the I position, the sub-problem can be obtained, that is, two games in 1*i-3 and 1 * (n-i-2), and a SG template is available; */# include <stdio.h> # include <cstdlib># include <cstring># include <iostream>using namespace std;int sg[2100];inline int D FS (int x) { if (x < 0) return 0; if (Sg[x] >= 0) return sg[x]; int mex[2100] = {0}; It is worth noting that this is not written in front of the function if judgment; for (int i = 1;i <= x;i++) { int t = DFS (i-3) ^ dfs (x-i-2); Mex[t] = 1; } for (int i = 0;;; i++) if (!mex[i]) return sg[x] = i;} int main () { int n; memset (sg,-1,sizeof (SG)); while (~SCANF ("%d", &n)) { if (DFS (n)) puts ("1"); Else puts ("2"); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Poj-3537-crosses and Crosses