1299: [LLH邀请赛]巧克力棒
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 469 Solved: 269
[ Submit][ Status][ Discuss]
Description
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
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
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。
Source
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,A[20];
bool Dfs(int x,int sum,int tot)
{
if (!sum && tot) return 1;
if (x > n) return 0;
if (Dfs(x + 1,sum,tot)) return 1;
if (Dfs(x + 1,sum ^ A[x],tot + 1)) return 1;
return 0;
}
int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif
for (int I = 1; I <= 10; I++)
{
scanf("%d",&n);
for (int i = 1; i <= n; i++) scanf("%d",&A[i]);
puts(Dfs(1,0,0) ? "NO" : "YES");
}
return 0;
}