
算法设计
文章平均质量分 67
hbjiaxiaoxue
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
棋盘问题
#include using namespace std; //特殊方格的值赋为0,三个一样的数字表示一个骨牌 //tr:棋盘左上角方格的行号 //tc:棋盘左上角方格的列号 //dr:特殊方格的行号 //dc:特殊方格的列号 int tile = 1; int ** Bord; //int Bord[8][8]={0}; void ChessBord(int tr,i原创 2011-12-05 21:45:51 · 393 阅读 · 0 评论 -
动态规划解决流水作业调度(Johnson法则)
#include #include using namespace std; #include #include #define random(x) (rand()%x) typedef struct { int key; //以Ai还是Bi作为关键字排序 bool job;//标志是Ai>Bi还是Ai<Bi型,从而分别归在N1或N2集合中 int index;//将它作为第index个作原创 2011-12-15 20:55:34 · 3310 阅读 · 0 评论 -
递归分治解决快速排序和限行时间选择
#include using namespace std; #include #include #define Random(x) (rand()%x) template void Swap(Type &m,Type &n){//交换两个数 Type temp = m; m = n; n = temp; } template int Partition(Type a[],int p,in原创 2011-12-14 21:19:20 · 788 阅读 · 0 评论 -
动态规划解决最大字段和
#include using namespace std; int MaxSum(int n,int *a,int &besti,int &bestj){ int sum = 0,starthere,b = 0; besti = bestj = 1; //b存放临时的和besti和bestj分别保存最佳开始和结束位置,starthere临时存放起始位置 for(int i = 1;i <原创 2011-12-14 20:20:52 · 641 阅读 · 0 评论 -
动态规划解决0-1背包问题
#include using namespace std; #include template Type min(Type a,Type b){ return a > b ? b:a; } template Type max(Type a,Type b){ return a < b ? b:a; } template void Knapsack(Type *v,int *w,int原创 2011-12-13 22:06:43 · 488 阅读 · 0 评论 -
哈夫曼编码
#include using namespace std; #include #include #define MAX_CODE 10 class HNode{ public: char c;//节点的字符 int weight;//节点的权重,即为出现的频率 int lchild;//节点的左孩子的编号 int rchild;//节点的右孩子的编号 char code[MAX_C原创 2011-12-13 21:24:17 · 615 阅读 · 0 评论 -
动态规划解决最长公共子序列
#include #include #include using namespace std; int c[10][10]; int b[10][10]; void LCSLength(int m,int n,char *x,char *y,int c[10][10],int b[10][10]){ int i,j; for(i = 0;i <= m;i++) c[i][0] = 0原创 2011-12-12 21:10:36 · 468 阅读 · 0 评论 -
动态规划解决矩阵连乘
#include using namespace std; #include /*p是一维数组,记录矩阵的规模(第一个矩阵的行和其余矩阵的列); n是矩阵的个;m是二维数组,记录计算A[i:j],1<=i<=j<=n所需要的最少数乘次数m[i][j]; 相对应于m[i][j]的断开位置k记为s[i][j]*/ void MatrixChain(int *p,int n,int **m,int原创 2011-12-12 19:16:39 · 395 阅读 · 0 评论 -
快速排序
#include using namespace std; template void Swap(Type &x,Type &y){ Type temp = x; x = y; y = temp; } template int Partition(Type a[],int p,int r){ int i = p,j = r + 1; Type x = a[p]; while(tru原创 2011-12-08 22:10:01 · 357 阅读 · 0 评论 -
一维最接近点对(递归分治)
//一维情况下的最接近点对 #include using namespace std; #include #include #include #include #define maxint 1000 template void Swap(Type &a,Type &b){ Type temp = a; a = b; b = temp; } /*template Type min(Typ原创 2011-12-17 21:45:25 · 1096 阅读 · 0 评论 -
非递归合并排序
#include using namespace std; #include int b[5]; template void Merge(Type c[],Type d[],int l,int m,int r){ int i = l,j = m+1,k = l; while( (i <= m) && (j <= r) ) { if(c[i] <= c[j]) d[k++] =原创 2011-12-08 20:15:23 · 383 阅读 · 0 评论 -
递归合并排序
#include using namespace std; #include int b[5]; template void Merge(Type c[],Type d[],int l,int m,int r){ int i = l,j = m+1,k = l; while( (i <= m) && (j <= r) ) { if(c[i] <= c[j]) d[k++] =原创 2011-12-08 20:02:12 · 431 阅读 · 0 评论 -
递归分治解决全排列问题
#include using namespace std; template inline void Swap(Type &a,Type &b){ Type temp = a; a = b; b = temp; } template void Perm(Type list[],int k,int m){ if(k == m) { for(int i = 0;i<=m;i++)原创 2011-12-08 16:16:10 · 496 阅读 · 0 评论 -
流水作业调度
#include #include using namespace std; #include #include #define random(x) (rand()%x) typedef struct { int key; //以Ai还是Bi作为关键字排序 bool job;//标志是Ai>Bi还是Ai int index;//将它作为第index个作原创 2011-12-05 21:47:27 · 707 阅读 · 0 评论 -
回溯法解决装载问题
#include #include using namespace std; typedef int* pointer; template class Loding{ friend Type MaxLoding(Type [],Type,int,int[]); private: void Backtrack(int i);原创 2011-12-05 21:43:57 · 1296 阅读 · 1 评论 -
0-1背包 动态规划
#include #include using namespace std; #include typedef struct{ int index;//物品的编号 int w;//物品的重量 int v;//物品的价值 }Goods; int min(int a,int b) { return a } int max(int原创 2011-12-05 21:48:45 · 404 阅读 · 0 评论 -
单源最短路径
#include #include using namespace std; #define maxint 1000 typedef int* pointer; void Dijkstra(int n,int v,int *dist,int *prev,int **c){ bool *s = new bool[n+1];//顶点i是否属于集合s for(int原创 2011-12-05 21:46:38 · 446 阅读 · 0 评论 -
动态规划解决装载问题
#include #include typedef int* pointer; int min(int a,int b){ return a > b? b:a; } int max(int a,int b){ return a > b? a:b; } void LodingC1(int C1,int* w,int n,int原创 2011-12-05 21:44:58 · 1919 阅读 · 2 评论 -
单源最短路径(贪心算法)
#include using namespace std; #include #define maxint 999 typedef int* pointer; template void Dijkstra(int n,int v,Type *dist,int *prev,Type **c){ //v是源点,dist记录源点到每一个顶点的最短距离,prev记录前一个顶点 //c是边距离矩阵 b原创 2011-12-16 20:23:29 · 884 阅读 · 0 评论