You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

#include <iostream>
#include <cstring>
using namespace std;
const int N = 55, M = 50060;
int n, f[N][M];
int sg(int a, int b) {
if (f[a][b] != -1) return f[a][b];
int &s = f[a][b];
if (!a) return b & 1; // 如果能转移到必败态
if (b == 1) return sg(a + 1, b - 1);
if (a && !sg(a - 1, b)) return s = 1; // 取a
if (b && !sg(a, b - 1)) return s = 1; // 合并b,取b
if (a && b > 1 && !sg(a - 1, b + 1)) return s = 1; // 合并a,b
if (a > 1 && !sg(a - 2, b == 0 ? b + 2 : b + 3)) return s = 1; // 合并a
return s = 0;
}
int main() {
int T;
scanf("%d", &T);
memset(f, -1, sizeof f);
f[1][0] = f[2][0] = 1;
f[3][0] = 0;
while (T--) {
scanf("%d", &n);
int a = 0, b = -1;
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
if (x == 1)
a++;
else
b += x + 1;
}
if (b < 0) b = 0;
if (sg(a, b))
puts("YES");
else
puts("NO");
}
return 0;
}