hdu 1848 sg博弈模版題

2022-09-03 12:09:12 字數 1571 閱讀 1759

/*

計算從1-n範圍內的sg值。

array(儲存可以走的步數,array[0]表示可以有多少種走法)

array需要從小到大排序

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)}}

}view code

//

i'm lanjiangzhou//c

#include #include

#include

#include

#include

#include

//c++

#include #include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using

namespace

std;

//*************************output*************************

#ifdef win32

#define int64 "%i64d"

#define uint64 "%i64u"

#else

#define int64 "%lld"

#define uint64 "%llu"

#endif

//**************************constant***********************

#define inf 0x3f3f3f3f

//aply for the memory of the stack

//#pragma comment (linker, "/stack:1024000000,1024000000")

//end

/*const int maxn =1010;

int k;

int fibo[maxn],f[maxn];

int mex(int p);

for(int i=0;i*/

const

int maxn =1010

;int

sg[maxn],hash[maxn];

intfibs[maxn];

void

fib()

return;}

void

getsg()

for(int j=0;j<=maxn;j++)}}

return;}

intmain()

else}}

HDU1848(SG,學習,模板)

題意 今天,又乙個關於fibonacci的題目出現了,它是乙個小遊戲,定義如下 1 這是乙個二人遊戲 2 一共有3堆石子,數量分別是m,n,p個 3 兩人輪流走 4 每走一步可以選擇任意一堆石子,然後取走f個 5 f只能是菲波那契數列中的元素 即每次只能取1,2,3,5,8 等數量 6 最先取光所有...

HDU1848,SG函式,簡單應用示例

先理解怎麼樣用!然後再弄明白為什麼這樣用。首先定義mex minimal excludant 運算,這是施加於乙個集合的運算,表示最小的不屬於這個集合的非負整數。例如mex 3 mex 0 mex 0。對於乙個給定的有向無環圖,定義關於圖的每個頂點的sprague grundy函式g如下 g x m...

HDU 1848 博弈SG函式

題目大意 任何乙個大學生對菲波那契數列 fibonacci numbers 應該都不會陌生,它是這樣定義的 f 1 1 f 2 2 f n f n 1 f n 2 n 3 所以,1,2,3,5,8,13 就是菲波那契數列。在hdoj上有不少相關的題目,比如1005 fibonacci again就是...