hdu 1536 (S-Nim) SG解法
来源:互联网 发布:网络扫描工具有什么用 编辑:程序博客网 时间:2024/05/16 07:58
这题折腾了好久,一直不知道怎么求解SG,感觉用递归的方法会超时,最后看代码,采用记忆某些已知的SG的方式,递归求解。其中还爆内存两次,是因为递归中的数组空间开辟过大,递归层次多了,很容易爆的。
code:
#include <iostream>#include <algorithm>using namespace std;int SG[10001];int setNum;int set[101];int M,N;int getSG(int value){int i =0 ;bool mex[101]={0};for (i = 0 ; i < setNum ; i++){int temp = value - set[i];if (temp < 0)break;if (SG[temp] == -1)SG[temp] = getSG(temp);mex[SG[temp]] = true;}for (i = 0 ; ; i++)if (!mex[i])break;return i;}int main(){int temp ;while (cin>>setNum && setNum){ memset(SG,-1,sizeof(SG));SG[0]=0;for(int i =0 ; i < setNum ; i++){cin>>set[i];} sort(set,set+setNum);cin>>M;while(M--){int ans =0 ;cin>>N;for (int i =0 ; i < N ; i++){ cin>>temp;if(SG[temp] == -1)SG[temp] = getSG(temp);ans^=SG[temp];}if (ans)cout<<"W";else cout<<"L";}cout<<endl;}return 0;}
- hdu 1536 (S-Nim) SG解法
- HDU 1536 S-Nim SG函数 Nim
- SG函数 hdu 1536 S-Nim
- hdu 1536 S-Nim sg函数
- HDU 1536 S-Nim (SG定理)
- HDU 1536 S-Nim 求SG函数
- HDU 1536 - S-Nim(SG)
- hdu 1536 S-Nim (sg函数模版)
- S-Nim - HDU 1536 SG函数
- HDU 1536(sg博弈) S-Nim
- HDU 1536 S-Nim(sg函数)
- HDU 1536 S-Nim (SG函数)
- HDU 1536 S-Nim [SG函数]【博弈】
- HDU 1536 S-Nim(SG经典博弈)
- HDU 1536 S-Nim(SG博弈)
- [hdu 1536 S-Nim] SG 函数
- HDU 1536 S-Nim(sg函数)
- HDU 1536 S-Nim 博弈,SG函数
- 《30天精通iPhone手机编程》-Day20-DJ混音器
- Const指针与Const常量的在C编译器之间的匹配
- android 分享带图片的信息到彩信,微薄====
- 搭建VS2005 Wince开发环境
- poj 1969 Count on Canton
- hdu 1536 (S-Nim) SG解法
- epoll 的 EPOLLET 和 EPOLLLT
- Zend Framework模块创建
- 电脑时代新尴尬:提笔忘字
- 看透了
- 如何调用这个dll的窗体?
- Enumeration 与 Iterator 学习笔记
- 如果你没有可用分.可是有PHP方面简单问题.可以直接留言给我,我会尽量的回答。
- 编程之美读书笔记:买票找零