TBL和X用巧克力棒玩游戏。每次一人可以从盒子里取出若干条巧克力棒,或是将一根取出的巧克力棒吃掉正整数长度。TBL先手两人轮流,无法操作的人输。 他们以最佳策略一共进行了10轮(每次一盒)。你能预测胜负吗?
Input
输入数据共20行。 第2i-1行一个正整数Ni,表示第i轮巧克力棒的数目。 第2i行Ni个正整数Li,j,表示第i轮巧克力棒的长度。
Output
输出数据共10行。 每行输出“YES”或“NO”,表示TBL是否会赢。如果胜则输出"NO",否则输出"YES"
Sample Input
3 11 10 15 5 13 6 7 15 3 2 15 12 3 9 7 4 2 15 12 4 15 12 11 15 3 2 14 15 3 3 16 6 4 1 4 10 3 5 8 7 7 5 12
Sample Output
YES NO YES YES YES NO YES YES YES NO
Hint
20%的分数,N<=5,L<=100。
40%的分数,N<=7。 50%的分数,L<=5,000。
100%的分数,N<=14,L<=1,000,000,000。
每次既可以取出若干条,也可以吃N+长度;
思路:我们先手想要赢,必须选出部分巧克力棒使得该部分的 xor和 ==0 ,这样对方就只有必败的局面了;
那么此时如果对方接着抽取巧克力棒,那么此时的 xor !=0 ,那么我们只需取出部分使得剩下的 xor==0 即可;
所以解决方案就是看是否有xor==0 的子序列,那么我们 dfs 即可;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 500005
#define inf 0x3f3f3f3f
#define INF 999999999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const int mod = 10000007;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-7
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }
int n; int a[maxn];
bool fg;
int dfs(int x, int use, int now) {
if (x == n + 1) {
if (use >= 1 && now == 0)fg = 1;
return 0;
}
dfs(x + 1, use, now); dfs(x + 1, use + 1, now^a[x]);
}
int main()
{
//ios::sync_with_stdio(false);
for (int i = 1; i <= 10; i++) {
fg = 0; rdint(n);
for (int j = 1; j <= n; j++)rdint(a[j]);
dfs(1, 0, 0);
if (fg)cout << "NO" << endl;
else cout << "YES" << endl;
}
return 0;
}