Network Flow Template (SAP)
This algorithm was named for Shortest Augmenting Path (SAP).. From an OIer, at about year 2010.IntroductionTotal of n nodes, m edges.S is source node means 'source'.T is sink node means 'target'.m...
Treap
简介Treap is Tree + Heap, each node have two property : Key, and Priority.Using key can format the Binary tree, and using Priority can make a heap.代码struct Treap {
int key,pri;
int cnt;
T...
Heap+Dijkstra
练习题:http://poj.org/problem?id=3169Dijkstra的过程InitializationSet dist[all]=∞ and set dist[S]=0;
push S into Heap;Mainwhile (!heap.empty()) {
HeapItem p=heap.pop();
if (dist[p] != p.distence) ...
LeetCode 664. Strange Printer 解题报告
题目给了个字符串,问打印几次能得到之。想了半天 其实可以用记忆化搜索做 这个dp方程想做的简便 也是挺难想的先将原字符串去重,得到新的字符串ss。设dp[i][j]为字符串ss[i...j]所需要的最小次数,有如下条件:dfs(int left, int right) {
...calculate...
return dp[left][right];
}
初始条件: dp[i...
atCoder.jp Tenka1 E - CARtesian Coodinate
先上官方解题报告题目http://tenka1-2017.contest.atcoder.jp/tasks/tenka1_2017_e有n条线,这n条线交了n(n-1)/2个点找到一个点,到这些交点的Manhatten距离之和最小。题解分别计算x和y坐标,先说结论:分别对于x坐标和y坐标,如果有奇数个点,所取的点必然是这些交点的中位数。如果有偶数个点,所取得点必为中间两个点最小的那个。理由:...