博弈论与Nim游戏的SG函数
很有趣,看了许多资料,回忆起了好多。博弈论不妨想像成一个棋盘,只有一个人来玩。(但是必胜/必败还是指的两人交替)N-Position 当前state必胜。P-Position 当前state必败。因此,任意一种state只能是P/N两种局面。N-Position == It have a chance into P-Position state at the next step, any c...
Hungarian Algoritim Template.
For Bipartite Graph..We Named left Node by 0,1,2,3,4,5...And the Right Node's names are also 0,1,2,3,4,5...For each time we call dfs(), we always stand on the left side, to watch the right side.Tem...
Longest increasing subsequence
https://en.wikipedia.org/wiki/Longest_increasing_subsequenceProblemSelect some item in array, and keep them ascending.e.g.: 0 8 2 9 3 1 7ans ==> 0 2 3 7 len=4Method1Binary Indexed TreeO(nlogn)ht...
Shuffle & next-permutation
Fisher-Yates shuffle Modern method. https://en.wikipedia.org/wiki/Fisher-Yates_shuffle#Modern_method 易于理解,从最后一个开始loop,在他之前(包括他本身)随便找一个,跟他swap。vector<int> shuffle(vector<int> a) {
fo...
Suffix array 后缀数组
Introduction模版中涉及了若干个变量array ss[] : 待处理的字符串pos : 表示ss[pos],这个下标,通常指ss[pos->...]这个suffixarray rank[pos] : suffix ss[pos->...] 排第几。array sa[k] or Ith[k] : 排名第k-th的suffix在哪(指的是ss[Ith[k]->...]...