
<<算法导论>>
文章平均质量分 74
MiniSheep_CS
编程者如上帝,可以创造万物。
展开
-
算法导论(LCS最长公共子序列)
真动态规划版(自底而下):#includeusing namespace std;const int maxn = 10001;int m,n;char b[maxn][maxn]; //回溯时保存路径int c[maxn][maxn]; //最长子序列void LCS(char *x,char *y){ int i,j; for(i=0;i<=m;i++)原创 2015-04-13 09:40:42 · 450 阅读 · 0 评论 -
最大堆实现堆排序
#includeusing namespace std;const int maxn = 100001;int Parent(int i){ return i / 2;}int Left(int i){ return 2 * i; }int Right(int i){ return 2 * i + 1;}void Max_heapify(int *a,int原创 2015-05-07 16:13:11 · 349 阅读 · 0 评论 -
算法导论-KMP模版
#include#include#includeusing namespace std;const int maxn = 10001;int next[maxn];void Compute(char *p) //匹配串和自己的next值{ int m = strlen(p); memset(next,0,sizeof(next)); next[1] =原创 2015-05-18 19:12:02 · 429 阅读 · 0 评论 -
DFS遍历图代码(算法导论思路实现)
#include#include#include#includeusing namespace std;const int maxn = 10005;int color[maxn]; //0代表白色,1代表灰色,2代表黑色vector vec[maxn]; //邻接表 int step; //全局变量代表总步数int stime[maxn]; //每个点遍历的时候的起始时间i原创 2015-07-14 10:57:58 · 558 阅读 · 0 评论 -
DFS拓扑排序(算法导论思路)
#include#include#include#include#include#includeusing namespace std;const int maxn = 10005;int color[maxn]; //0代表白色,1代表灰色,2代表黑色vector vec[maxn]; //邻接表 int step; //全局变量代表总步数int stime[maxn];原创 2015-07-14 12:31:06 · 848 阅读 · 0 评论