博弈,求SG值
2016-07-29 16:48
316 查看
#include <iostream> using namespace std; #define MAX 1005 /* 计算从1-n范围内的SG值。 Array(存储可以走的步数,Array[0]表示可以有多少种走法) Array[]需要从小到大排序 /*HDU1847博弈SG函数 1.可选步数为1-m的连续整数,直接取模即可,SG(x) = x % (m+1); 2.可选步数为任意步,SG(x) = x; 3.可选步数为一系列不连续的数,用GetSG(计算) */ int SG[MAX], hash[MAX]; void GetSG(int Array[], int n = MAX-1) { int i, j; memset(SG, 0, sizeof(SG)); for(i = 0; i <= n; i++) { memset(hash, 0, sizeof(hash)); for(j = 1; j <= Array[0]; j++) { if(i < Array[j]) break; hash[SG[i - Array[j]]] = 1; } for(j = 0; j <= n; j++) { if(hash[j] == 0) { SG[i] = j; break; } } } }
相关文章推荐
- linux sed命令详解
- c语言描述的静态查找表
- 广搜:吃豆子
- 解决部分月份绩效无法显示的问题:timestamp\union al\autocommit等的用法
- 由浅入深:自己动手开发模板引擎——置换型模板引擎(一)
- 探索篇
- 14.9 InnoDB Row Storage and Row Formats
- Oracle的REDO和UNDO
- The project: xxxxx which is referenced by the classpath, does not exist
- UVA 11624 <《经典bfs》迷宫逃亡之追击问题---火追人>
- SQLBulkCopy使用
- C#相等性比较(转)
- 单例模式实例详解
- <mate name="viewport">移动端设置详解
- maven 简单使用
- 剑指offer——栈的压入、弹出序列
- HDU 2830 Matrix Swapping II(最大完全子矩阵之可移动列)
- gitlab备份及恢复
- iOS中关于旋转屏的控制
- c++、java CRC16算法