hdu 5724 Chess (sg函数 + 状态压缩)
来源:互联网 发布:网络修真小说研究 编辑:程序博客网 时间:2024/05/21 22:31
分析:
- 用二进制来压缩当前状态。
- 没有子状态的其sg为0(这在操作中就可自动实现。
- 对于当前状态的子状态进行枚举,二进制数一定是减小到所以符合sg函数转移。
- 求所有sg值的异或。
预处理sg函数的时间复杂度为
#include <iostream>#include <cstring>#include <cstdio>using namespace std;struct jibancanyang{ int chess[1 << 21]; bool have[30]; void pre() { for (int i = 1; i < 1 << 20; i++) { memset(have, 0, sizeof(have)); for (int j = 0; j < 20; j++) { if (i & (1 << j)) { int k; for (k = j - 1; k >= 0; k--) { if (!(i & (1 << k))) break; } if (k >= 0) { int temp = i ^ (1 << j) | (1 << k); have[chess[temp]] = true; } } } int cnt = 0; while (have[cnt]) cnt++; chess[i] = cnt; } } void run() { pre(); int T, n; scanf("%d", &T); while (T--) { scanf("%d", &n); int ans = 0; while (n--) { int x, s = 0, bit; scanf("%d", &x); while (x--) { scanf("%d", &bit); s ^= 1 << (20 - bit); } ans ^= chess[s]; } puts(ans ? "YES" : "NO"); } }}ac;int main(){ //freopen("in.txt", "r", stdin); ac.run(); return 0;}
0 0
- hdu 5724 Chess (sg函数 + 状态压缩)
- HDU 5724 Chess(博弈,SG函数)
- hdu 5724 Chess(SG函数)
- hdu 5724 Chess (SG函数)
- hdu 5724 - chess (sg函数)
- hdu 5724 Chess(sg函数)
- hdu 5724 Chess SG函数
- (组合博弈)(sg函数模版)HDU 5724 Chess
- HDU 5724 Chess (博弈 状压+sg函数)
- HDU 5724-Chess-博弈论-sg函数
- HDU 5724 Chess(SG函数 Nim博弈)
- HDU 5724 chess sg函数学习
- hdu 5724 Chess [状压+SG函数]【博弈】
- HDU-5724 Chess(SG函数+状压)
- hdu5724——chess(博弈)(状态压缩dp+sg函数)
- HDU5724(多校第一场)——Chess(sg函数,状态压缩)
- hdu 5742 chess SG函数
- hdu 5724 Chess(sg博弈)
- 蓝桥杯 PREV-5历届试题 错误票据
- opencv4android常用变换(二)
- Network 【SVN 命令行操作】
- 蓝桥杯 ADV-144算法提高 01背包
- 【Arduino官方教程】数字处理示例(六):音调键盘
- hdu 5724 Chess (sg函数 + 状态压缩)
- iOS多线程开发——NSThread的简单运用
- css层叠性规则
- dll 导出函数名的那些事
- android studio ctrl+左键 查看系统源码
- 蓝桥杯 ALGO-30算法训练 入学考试(01背包,动态规划)
- 套接字描述符的理解
- cocoa touch——UIView——NSLayoutAnchor
- sum of two integers