HDU 5724-Chess-博弈论-sg函数
来源:互联网 发布:淘宝培训kehuda 编辑:程序博客网 时间:2024/05/18 01:59
对于每一个状态,暴力求出所有后继状态,通过SG函数求到该状态的SG值。。
这题用dfs+记忆化暴力写就好了
当时直接枚举了所有情况打表。。。存了所有后继,差点爆内存,改成short才过
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <cstdio>#include <algorithm>#include <queue>#include <map>#include <set>#include <vector>#include <iostream>#include<queue>#define LL long long#define MAX 10005using namespace std;/*int A[MAX];bool win[1<<21];void solve(){ for(int num=0;num<20;num++) { for(int i=0;i<20;i++) { int now=pow(2,i+1)-1; sg[now]=0; } }}*/short idx[500+(1<<20)];short que[500+(1<<20)][25];short sg[500+(1<<20)];short cal_sg(int x){ if (sg[x]!=-1) return sg[x]; int vis[25]; memset(vis,0,sizeof vis); for (int i=1; i<=idx[x]; i++) { vis[que[x][i]]=1; } for (int i=0;; i++) if (vis[i]==0) return sg[x]=i;}long long tmpp=0;void BinaryRecursion(int n){ int a; a=n%2; n=n>>1; if (n==0) ; else BinaryRecursion(n); tmpp=tmpp*10+a;}void get(){ int vis[25]; int all=1<<20; for (int i=0; i<all; i++) { int state=i; sg[i]=cal_sg(state); for (int j=0; j<20; j++) { if ((1<<j)&state) { int temp=state|((1<<j)-1); temp=~temp; if(0==temp) continue; int low_zero=temp&-temp; //lowbit int father=state^(1<<j); father=father| (low_zero); //printf("%d ***\n",father); if (father >=(all)) continue; que[father][++idx[father]]=cal_sg(state); // que[father].push_back(state); } } }}int main(){ memset(sg,-1,sizeof sg); memset(idx,0,sizeof idx); // freopen("out.txt","w",stdout); get(); // sg[0]=0; int t; cin>>t; while(t--) { int n,m; scanf("%d",&n); int ans=0; for (int i=1;i<=n;i++) { scanf("%d",&m); int state=0; int x; for (int j=1;j<=m;j++) { scanf("%d",&x); state=state|(1<<(20-x)); } ans^=sg[state]; } if (ans) printf("YES\n"); else printf("NO\n"); } 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函数)
- HDU 5724 Chess(SG函数 Nim博弈)
- hdu 5724 Chess (SG函数)
- HDU 5724 chess sg函数学习
- hdu 5724 Chess [状压+SG函数]【博弈】
- HDU-5724 Chess(SG函数+状压)
- hdu 5742 chess SG函数
- HDU 5724 Chess(博弈论)
- HDU 5724 Chess (状压+sg)
- HDU 5724 Chess 从懵逼到学会 SG函数
- hdu 5724 Chess (sg函数 + 状态压缩)
- (组合博弈)(sg函数模版)HDU 5724 Chess
- 初探MW302
- Sharding
- Linux进程通信(二)IPC消息队列
- linux文件系统
- FM radio_模块测试学习
- HDU 5724-Chess-博弈论-sg函数
- Core Spotlight和深度链接结合使用(上)
- UVA - 10537 The Toll! Revisited dijkstra反向
- 数据结构(java)---MyLinkedList
- 引用头文件却找不到相对应的类
- hdu 2846 Repository
- 正则表达式
- HDU 5723-A - Abandoned country-最小生成树+树dp
- chapter 1 let 和 const