A and B play a game. There are n lines. A and B color them by turns (A first). One can only color a segment of a line, with length 2, which has not be colored, and the distance between a segment end point and the line's end point is a interger. When one can not color, he loses.
Input
There are several test cases. The first line of a case is a positive interger n, the next line contain n positive intergers, represent the lengths of the n lines. The sum of the lengths do not exceed 50.
Output
If A can win output a "Yes", else output a "No".
Note: you should consider A and B a clever enough.
Sample Input
2
2 4
1
9
Sample Output
Yes
No
水题~
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<memory.h>
using namespace std;
int sg[55];
int dfs(int x)
{
if(x<2) return sg[x]=0;
if(sg[x]!=-1) return sg[x];
bool g[1010]={0};
for(int i=x-2;i>=0;i--)
{
int t=dfs(i)^dfs(x-i-2);
g[t]=1;
}
for(int i=0;;i++)
if(g[i]==0) return sg[x]=i;
}
int main()
{
memset(sg,-1,sizeof(sg));
int n;
while(scanf("%d",&n)!=EOF)
{
int num;
int ans=0;
for(int i=0;i<n;i++)
{
scanf("%d",&num);
ans^=dfs(num);
}
if(ans) puts("Yes");
else puts("No");
}
}