Game theory
Equivalent to put X position, left and right 4 grid can no longer put X, who has nowhere to put lose.
n<=2000
The direct enumeration of subsequent States, the force of the SG function can be.
Example: 0000000->x. 0000/. x. 000/.. X.. 00/0..x. 0/00..x.
Memory Search write hung up ... or sequential DP-based = = (similar to S-nim, brute force for SG function)
1 Source Code2Problem:3537user:sdfzyhy3 memory:692k time:141ms4language:g++result:accepted5 6 Source Code7 8 //POJ 35379#include <cmath>Ten#include <queue> One#include <vector> A#include <string> -#include <cstdio> -#include <cstring> the#include <cstdlib> -#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) + #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + using namespacestd; A at intGetint () { - intR=0, c=1;CharCh=GetChar (); - for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') c=-1; - for(; isdigit (ch); Ch=getchar ()) r=r*Ten+ch-'0'; - returnr*C; - } in Const intn= ., inf=~0u>>2; - Const Doubleeps=1e-9; to /******************template***********************/ + intDp[n],n; - BOOLVis[n],mark[n]; the * intMain () { $n=getint ();Panax Notoginsengdp[0]=0; dp[1]=dp[2]=dp[3]=1; -F (I,4, N) { thememset (Mark,0,sizeofmark); +mark[dp[i-3]]=mark[dp[i-4]]=mark[dp[i-5]]=1; A for(intj=1; j<=i-5-j;j++) themark[dp[j]^dp[i-5-j]]=1; +F (J,0, N)if(!mark[j]) {dp[i]=j; Break;} - } $printf"%d\n", Dp[n]?1:2); $ return 0; -}
View Code
"POJ" "3537" crosses and crosses