怎么又是博弈论。。。我去

Orz hzwer,这道题其实是可以转化成Nim游戏的!

"第一步:

先从n根巧克力棒中取出m(m>0)根,使得这m根巧克力棒的xor和为0,同时使得剩下的n-m根巧克力棒无论怎么取,xor和都不为0。

m根巧克力棒的xor和为0 <=>把nim游戏的必败状态留给对方

剩下的n-m根巧克力棒无论怎么取,xor和都不为0 <=>  m为巧克力棒的xor和为0的最长子序列

第二步:

第一步以后,对手就面临一个必败状态的nim游戏。

如果他从n-m根中取新的巧克力棒,实际上就是新建一个xor和不为0的nim游戏,这时轮到己方操作只要将这个新的nim游戏取到xor和为0即可。

也就是让对方再次面临所有nim游戏均为必败状态的局面。"

于是只要寻找m是否存在即可,由于n = 14,深搜即可。

 /**************************************************************
Problem: 1299
User: rausen
Language: C++
Result: Accepted
Time:8 ms
Memory:804 kb
****************************************************************/ #include <cstdio> using namespace std;
int n, a[];
bool flag; inline int read(){
int x = , sgn = ;
char ch = getchar();
while (ch < '' || ch > ''){
if (ch == '-') sgn = -;
ch = getchar();
}
while (ch >= '' && ch <= ''){
x = x * + ch - '';
ch = getchar();
}
return sgn * x;
} void dfs(int x, int cnt, int X){
if (x == n + ){
if (!X && cnt) flag = ;
return;
}
if (flag) return;
dfs(x + , cnt, X);
if (flag) return;
dfs(x + , cnt + , X ^ a[x]);
} int main(){
for (int t = ; t <= ; ++t){
flag = ;
n = read();
for (int i = ; i <= n; ++i)
a[i] = read();
dfs(, , );
printf(flag ? "NO\n" : "YES\n");
}
return ;
}
04-30 11:42