diff --git a/HDOJ/5724_tc_to_top.cpp b/HDOJ/5724_tc_to_top.cpp new file mode 100644 index 0000000..e76d896 --- /dev/null +++ b/HDOJ/5724_tc_to_top.cpp @@ -0,0 +1,55 @@ +#include +#include +int const MAX = 21; +int sg[1 << MAX], vis[MAX]; + +int get_sg(int sta) +{ + memset(vis, false, sizeof(vis)); + for(int i = 20; i >= 0; i--) + { + if(sta & (1 << i)) + { + int tmp = sta; + for(int j = i - 1; j >= 0; j--) + { + if(!(sta & (1 << j))) + { + tmp ^= ((1 << i) ^ (1 << j)); + vis[sg[tmp]] = true; + break; + } + } + } + } + for(int i = 0; i <= 20; i++) + if(!vis[i]) + return i; + return 0; +} + +int main() +{ + memset(sg, 0, sizeof(sg)); + for(int i = 0; i < (1 << 20); i++) + sg[i] = get_sg(i); + int T; + scanf("%d", &T); + while(T --) + { + int n, m, p, ans = 0; + scanf("%d", &n); + for(int i = 0; i < n; i++) + { + scanf("%d", &m); + int sta = 0; + while(m --) + { + scanf("%d", &p); + sta |= (1 << (20 - p)); + } + ans ^= sg[sta]; + } + printf("%s\n", ans ? "YES" : "NO"); + } +}