Quick Sort 和 Quick Sort
序这是一个历史遗留问题下文有两个函数 qsort和qsort2,其中qsort是对的,而qsort2会tle/wa?。。。直到现在还不知道是哪里的事儿。。囧rzTemplate#include <iostream>
using namespace std;
int a[100]={1,2,3,8,6,3,1,4,2,9,9,9,1}, n=13;
void qsort2(int ...
博弈论与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...