标签:long const using div ++ 记忆 pac 找规律 mem
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef long long ll; const int N=51,M=50055; inline int read(){ char c=getchar();int x=0,f=1; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘;c=getchar();} return x*f; } int n,f[N][M]; int dfs(int a,int b){ int &now=f[a][b]; if(now!=-1) return now; if(a==0) return now=b&1; if(b==1) return now=dfs(a+1,0); if(a && !dfs(a-1,b) ) return now=1; if(b && !dfs(a,b-1) ) return now=1; if(a && b && !dfs(a-1,b+1) ) return now=1; if(a>=2 && !dfs(a-2,b+2+(b!=0)) ) return now=1; return now=0; } int main(){ //freopen("in","r",stdin); int T=read(); memset(f,-1,sizeof(f)); while(T--){ n=read(); int x=0,y=0,a; for(int i=1;i<=n;i++){ a=read(); if(a==1) x++; else y+=a+1; } if(y) y--; puts(dfs(x,y) ? "YES" : "NO"); } }
标签:long const using div ++ 记忆 pac 找规律 mem
原文地址:http://www.cnblogs.com/candy99/p/6551284.html