HDU

来源:互联网 发布:文娱小说推荐知乎 编辑:程序博客网 时间:2024/06/11 21:55

Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the moved chess, move the chess to its right adjacent block. Otherwise, skip over these chesses and move to the right adjacent block of them. Two chesses can’t be placed at one block and no chess can be placed out of the chessboard. When someone can’t move any chess during his/her turn, he/she will lose the game. Alice always take the first turn. Both Alice and Bob will play the game with the best strategy. Alice wants to know if she can win the game.
Input
Multiple test cases.

The first line contains an integer T(T≤100)T(T≤100), indicates the number of test cases.

For each test case, the first line contains a single integer n(n≤1000)n(n≤1000), the number of lines of chessboard.

Then nn lines, the first integer of ith line is m(m≤20)m(m≤20), indicates the number of chesses on the ith line of the chessboard. Then m integers pj(1≤pj≤20)pj(1≤pj≤20) followed, the position of each chess.
Output
For each test case, output one line of “YES” if Alice can win the game, “NO” otherwise.
Sample Input
2
1
2 19 20
2
1 19
1 18
Sample Output
NO
YES

很明显的亦或求和
然后20个棋盘很明显状态压缩
然后就推一下后继状态…

很难写…

#include<bits/stdc++.h>using namespace std;template <class T> inline void in(T &x) {    T f = 1; char c; while ((c = getchar()) < '0' || c > '9') if (c == '-') f = -1;    x = c - '0';    while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0'; x *= f;}int sg[1<<21];int mp[50];int main(){    int T;    int he=0;    int bjb=1<<20;    for(int a=0;a<bjb;a++)    {        memset(mp,0,sizeof(mp));        for(int b=0;b<=20;b++)        {            if(a&(1<<b))            {                int tt=a;                for(int c=b-1;c>=0;c--)                {                    if(a&(1<<c))continue;                    tt^=((1<<b)^(1<<c));                    mp[sg[tt]]=1;                    break;                }            }        }        for(int b=0;b<=20;b++)        {            if(mp[b])continue;            sg[a]=b;            break;        }    }    cin>>T;    while(T--)    {        int n;        scanf("%d",&n);        int zhi=0;        for(int a=1;a<=n;a++)        {            int m,w;            scanf("%d",&m);            int gs=0;            for(int b=1;b<=m;b++)            {                scanf("%d",&w);                gs|=1<<(20-w);            }            zhi^=sg[gs];        }        if(zhi)printf("YES\n");        else printf("NO\n");    }}
原创粉丝点击