├── 第12章 概率算法 ├── 洗牌.cpp ├── 主元素问题.cpp ├── 八皇后问题.cpp ├── 整数因子划分.cpp ├── 素数测试问题.cpp └── 随机快速排序.cpp ├── 第3章 蛮力法 ├── 凸包问题.cpp ├── 最近点对.cpp ├── 选择排序.cpp ├── 顺序查找.cpp ├── 串匹配BF算法.CPP ├── 串匹配KMP.CPP └── 百元买百鸡问题.cpp ├── 第4章 分治法 ├── 归并排序.cpp ├── 快速排序.cpp ├── 最近对问题.cpp ├── 汉诺塔问题.cpp ├── 数字旋转方阵.cpp ├── 最大字段和问题.cpp ├── 棋盘覆盖问题.cpp └── Fibonacci序列.cpp ├── 第5章 减治法 ├── 二叉查找树.cpp ├── 堆排序.cpp ├── 折半查找.cpp ├── 插入排序.cpp ├── 选择问题.cpp ├── 淘汰冠军问题.cpp ├── 两个序列的中位数.cpp └── 假币问题.cpp ├── 第7章 贪心法 ├── 图着色问题.cpp ├── 埃及分数.cpp ├── 背包问题.cpp ├── TSP最近邻点.cpp ├── 多机调度问题.cpp ├── 活动安排问题.cpp └── 最小生成树PRIM.cpp ├── 第8章 回溯法 ├── 八皇后问题.cpp ├── 哈密顿回路.cpp ├── 图着色问题.cpp ├── 素数环.cpp └── 批处理作业调度.cpp ├── 第11章 近似算法 ├── 子集和问题.cpp ├── 装箱问题.cpp └── 求PI的近似值.cpp ├── 第2章 算法分析基础 ├── 冒泡排序.cpp ├── 合并排序.cpp ├── 顺序查找.cpp ├── 数组中求最小元素.cpp └── 起泡排序的比较和移动次数.cpp ├── 第6章 动态规划法 ├── 数塔问题.cpp ├── 0-1背包问题.cpp ├── 最优二叉查找树.cpp ├── 最长递增子序列.cpp ├── 近似串匹配问题.cpp ├── 多段图的最短路径问题.cpp ├── 多源点最短路径问题.cpp └── 最长公共子序列问题.cpp ├── 第1章 算法设计基础 ├── 短除法求最大公约数.cpp └── 欧几里德算法求最大公约数.cpp └── README.md /第12章 概率算法/洗牌.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第12章 概率算法/洗牌.cpp -------------------------------------------------------------------------------- /第3章 蛮力法/凸包问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第3章 蛮力法/凸包问题.cpp -------------------------------------------------------------------------------- /第3章 蛮力法/最近点对.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第3章 蛮力法/最近点对.cpp -------------------------------------------------------------------------------- /第3章 蛮力法/选择排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第3章 蛮力法/选择排序.cpp -------------------------------------------------------------------------------- /第3章 蛮力法/顺序查找.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第3章 蛮力法/顺序查找.cpp -------------------------------------------------------------------------------- /第4章 分治法/归并排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第4章 分治法/归并排序.cpp -------------------------------------------------------------------------------- /第4章 分治法/快速排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第4章 分治法/快速排序.cpp -------------------------------------------------------------------------------- /第4章 分治法/最近对问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第4章 分治法/最近对问题.cpp -------------------------------------------------------------------------------- /第4章 分治法/汉诺塔问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第4章 分治法/汉诺塔问题.cpp -------------------------------------------------------------------------------- /第5章 减治法/二叉查找树.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第5章 减治法/二叉查找树.cpp -------------------------------------------------------------------------------- /第5章 减治法/堆排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第5章 减治法/堆排序.cpp -------------------------------------------------------------------------------- /第5章 减治法/折半查找.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第5章 减治法/折半查找.cpp -------------------------------------------------------------------------------- /第5章 减治法/插入排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第5章 减治法/插入排序.cpp -------------------------------------------------------------------------------- /第5章 减治法/选择问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第5章 减治法/选择问题.cpp -------------------------------------------------------------------------------- /第7章 贪心法/图着色问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第7章 贪心法/图着色问题.cpp -------------------------------------------------------------------------------- /第7章 贪心法/埃及分数.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第7章 贪心法/埃及分数.cpp -------------------------------------------------------------------------------- /第7章 贪心法/背包问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第7章 贪心法/背包问题.cpp -------------------------------------------------------------------------------- /第8章 回溯法/八皇后问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第8章 回溯法/八皇后问题.cpp -------------------------------------------------------------------------------- /第8章 回溯法/哈密顿回路.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第8章 回溯法/哈密顿回路.cpp -------------------------------------------------------------------------------- /第8章 回溯法/图着色问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第8章 回溯法/图着色问题.cpp -------------------------------------------------------------------------------- /第8章 回溯法/素数环.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第8章 回溯法/素数环.cpp -------------------------------------------------------------------------------- /第11章 近似算法/子集和问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第11章 近似算法/子集和问题.cpp -------------------------------------------------------------------------------- /第11章 近似算法/装箱问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第11章 近似算法/装箱问题.cpp -------------------------------------------------------------------------------- /第12章 概率算法/主元素问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第12章 概率算法/主元素问题.cpp -------------------------------------------------------------------------------- /第12章 概率算法/八皇后问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第12章 概率算法/八皇后问题.cpp -------------------------------------------------------------------------------- /第2章 算法分析基础/冒泡排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第2章 算法分析基础/冒泡排序.cpp -------------------------------------------------------------------------------- /第2章 算法分析基础/合并排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第2章 算法分析基础/合并排序.cpp -------------------------------------------------------------------------------- /第2章 算法分析基础/顺序查找.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第2章 算法分析基础/顺序查找.cpp -------------------------------------------------------------------------------- /第3章 蛮力法/串匹配BF算法.CPP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第3章 蛮力法/串匹配BF算法.CPP -------------------------------------------------------------------------------- /第3章 蛮力法/串匹配KMP.CPP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第3章 蛮力法/串匹配KMP.CPP -------------------------------------------------------------------------------- /第3章 蛮力法/百元买百鸡问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第3章 蛮力法/百元买百鸡问题.cpp -------------------------------------------------------------------------------- /第4章 分治法/数字旋转方阵.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第4章 分治法/数字旋转方阵.cpp -------------------------------------------------------------------------------- /第4章 分治法/最大字段和问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第4章 分治法/最大字段和问题.cpp -------------------------------------------------------------------------------- /第4章 分治法/棋盘覆盖问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第4章 分治法/棋盘覆盖问题.cpp -------------------------------------------------------------------------------- /第5章 减治法/淘汰冠军问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第5章 减治法/淘汰冠军问题.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/数塔问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第6章 动态规划法/数塔问题.cpp -------------------------------------------------------------------------------- /第7章 贪心法/TSP最近邻点.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第7章 贪心法/TSP最近邻点.cpp -------------------------------------------------------------------------------- /第7章 贪心法/多机调度问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第7章 贪心法/多机调度问题.cpp -------------------------------------------------------------------------------- /第7章 贪心法/活动安排问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第7章 贪心法/活动安排问题.cpp -------------------------------------------------------------------------------- /第8章 回溯法/批处理作业调度.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第8章 回溯法/批处理作业调度.cpp -------------------------------------------------------------------------------- /第11章 近似算法/求PI的近似值.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第11章 近似算法/求PI的近似值.cpp -------------------------------------------------------------------------------- /第12章 概率算法/整数因子划分.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第12章 概率算法/整数因子划分.cpp -------------------------------------------------------------------------------- /第12章 概率算法/素数测试问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第12章 概率算法/素数测试问题.cpp -------------------------------------------------------------------------------- /第12章 概率算法/随机快速排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第12章 概率算法/随机快速排序.cpp -------------------------------------------------------------------------------- /第5章 减治法/两个序列的中位数.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第5章 减治法/两个序列的中位数.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/0-1背包问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第6章 动态规划法/0-1背包问题.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/最优二叉查找树.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第6章 动态规划法/最优二叉查找树.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/最长递增子序列.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第6章 动态规划法/最长递增子序列.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/近似串匹配问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第6章 动态规划法/近似串匹配问题.cpp -------------------------------------------------------------------------------- /第1章 算法设计基础/短除法求最大公约数.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第1章 算法设计基础/短除法求最大公约数.cpp -------------------------------------------------------------------------------- /第2章 算法分析基础/数组中求最小元素.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第2章 算法分析基础/数组中求最小元素.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/多段图的最短路径问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第6章 动态规划法/多段图的最短路径问题.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/多源点最短路径问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第6章 动态规划法/多源点最短路径问题.cpp -------------------------------------------------------------------------------- /第6章 动态规划法/最长公共子序列问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第6章 动态规划法/最长公共子序列问题.cpp -------------------------------------------------------------------------------- /第1章 算法设计基础/欧几里德算法求最大公约数.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第1章 算法设计基础/欧几里德算法求最大公约数.cpp -------------------------------------------------------------------------------- /第2章 算法分析基础/起泡排序的比较和移动次数.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WadeStack/Design-and-Analysis-of-Algorithms/HEAD/第2章 算法分析基础/起泡排序的比较和移动次数.cpp -------------------------------------------------------------------------------- /第4章 分治法/Fibonacci序列.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int Fib(int n); 4 | int fib(int n); 5 | int main() 6 | { 7 | 8 | int r=Fib(7); 9 | cout< 2 | using namespace std; 3 | const int N = 8; //假设求解8枚硬币问题 4 | int a[N] = {2, 2, 2, 2, 2, 1, 2, 2}; 5 | 6 | int Coin(int low, int high, int n); 7 | 8 | int main() 9 | { 10 | int i=Coin(0,7,8); 11 | cout<<"假币是第"< add2) //在第2组查找,下标范围low+num1~low+num1+num2-1 39 | return Coin(low + num1, low + num1 + num2 - 1, num2); 40 | else //在第3组查找,下标范围low+num1+num2~high 41 | Coin(low + num1 + num2, high, num3); 42 | } 43 | -------------------------------------------------------------------------------- /第7章 贪心法/最小生成树PRIM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | const int n = 6; 4 | const int MAX = 100; 5 | typedef struct 6 | { 7 | int lowcost; 8 | int adjvex; 9 | } Element; 10 | 11 | void Prim(int arc[n][n], int w); 12 | 13 | int main( ) 14 | { 15 | int arc[n][n] = {{MAX, 34, 46, MAX,MAX,19}, 16 | {34, MAX, MAX,MAX,12, MAX},{46, MAX, MAX, 17, MAX, 25}, 17 | {MAX, MAX, 17, MAX, 38, 25},{MAX, 12, 38, MAX, 26},{19, MAX, 25, 25, 26, MAX} 18 | }; 19 | Prim(arc, 0); 20 | return 0; 21 | } 22 | 23 | void Prim(int arc[n][n], int w) 24 | { 25 | int i, j, k; 26 | int min; 27 | Element shortEdge[10]; 28 | for (i = 0; i < n; i++) //初始化辅助数组shortEdge 29 | { 30 | shortEdge[i].lowcost = arc[w][i]; 31 | shortEdge[i].adjvex = w; 32 | } 33 | shortEdge[w].lowcost = 0; //将顶点0加入集合U 34 | for (i = 0; i < n - 1; i++) 35 | { 36 | for (min = 100, j = 0; j < n; j++) //寻找最短边的邻接点k 37 | { 38 | if((shortEdge[j].lowcost != 0) && (shortEdge[j].lowcost < min)) 39 | { 40 | min = shortEdge[j].lowcost; 41 | k = j; 42 | } 43 | } 44 | cout<