原创 最長公共子序列(LCS)

最長公共子序列(LCS)是一個在一個序列集合中(通常爲兩個序列)用來查找所有序列中最長子序列的問題。這與查找最長公共子串的問題不同的地方是:子序列不需要在原序列中佔用連續的位置 。 最長公共子序列問題是一個經典的計算機科學問題,也是

原创 數據結構之循環隊列(順序表實現)

#include<stdio.h> #include<malloc.h> #include<string.h> #define M 30 #define TRUE 1 #define FALSE 0 #define MAXSIZE 5

原创 數據結構之棧

#include<stdio.h> #include<malloc.h> #define ERROR 0 #define OK 1 #define STACK_INT_SIZE 10 /*存儲空間初始分配量*/ #define ST

原创 數據結構之循環鏈表

#include<stdio.h> #include<malloc.h> #include<string.h> #define M 30 #define TRUE 1 #define FALSE 0 #define MAXSIZE 5

原创 只有尾指針的循環鏈表

假設以帶頭結點的循環鏈表表示隊列,並且只設一個指針指向隊尾結點(不設隊頭指針),試編寫相應的置空隊列、入隊列、出隊列的算法。 #include<stdio.h> #include<malloc.h> #include<string.h

原创 codeforces Cloud Computing

Buber is a Berland technology company that specializes in waste of investor’s money. Recently Buber decided to transf

原创 約瑟夫環問題

n個數據元素構成一個環,從環中任意位置開始計數,計到m將該元素從表中取出,重複上述過程,直至表中只剩下一個元素。 思路 用一個無頭結點的循環單鏈表來實現n個元素的存儲。 循環單鏈表:尾指針指向頭結點。這樣指針可以循環移動。 技巧 1,

原创 區間

算法描述 For p:=1 to n do // p是區間長度,作爲階段。 for i:=1 to n do // i是窮舉的區間的起點 begin j:=i+p-1; // j是 區間的終點,這樣所有的區間就窮舉完畢 if j>n

原创 堆排序的模板

#include <bits/stdc++.h> #define N 1000 using namespace std; void max_heapify(int arr[], int left, int right) {

原创 快速排序模板

#include <bits/stdc++.h> #define N 1000 using namespace std; int QuickSort_partition(int arr[], int left, int right)

原创 Adjacent Bit Counts

For a string of n bits x1, x2, x3,…, xn, the adjacent bit count of the string (AdjBC(x)) is given by x1 ∗ x2 + x2 ∗ x

原创 用Java實現排列、組合算法

1、我們知道,排列個數的計算公式如下: AnmA^m_nAnm​ = n (n - 1) ⋯\cdots⋯ (n - m + 1) = n!(n−m)!\frac{ n ! }{( n - m ) ! }(n−m)!n!​ 組合個數

原创 KMP算法模板

int kmp(const string &T, const string &P) { if (P.empty()) return 0; vector<int> pi(P.size(), 0); for (i

原创 歸併排序模板

#include <cstdio> #include <cstdlib> #include <iostream> #define N 30100 using namespace std; int ans; void Merge(i

原创 CodeForces 712C Memory and De-Evolution

outputstandard output Memory is now interested in the de-evolution of objects, specifically triangles. He starts with