基本的博弈论算法,通过几组手写测试数据可以发现其中的规律,用不到sg函数
代码贴上
var f:Array[0..1000] of longint; t,i,k,h,j,m,n:longint; begin readln(t); for i:=1 to t do begin readln(n); k:=0; fillchar(f,sizeof(f),0); for j:=1 to n do begin read(f[j]); if f[j]=1 then inc(k); f[j]:=f[j]+f[j-1]; end; if f[n]=n then begin if n mod 3=0 then writeln('NO') else writeln('YES'); continue; end else if f[n]=n+1 then begin begin if (n-1) mod 3=0 then writeln('NO') else writeln('YES');continue; end; end else begin if (not odd(n+f[n]-1)) and (not odd(k)) then begin writeln('NO'); continue; end else writeln('YES'); end; end; end.