算法
042工作室
这个作者很懒,什么都没留下…
展开
-
(回溯法)批处理作业调度
public class FlowShop { static int n, // 作业数 f1, // 机器1完成处理时间 f, // 完成时间和 bestf; // 当前最优值 static int[][] m; // 各作业所需的 static int[] x; // 当前作业调度 static int[] bestx; // 当前最优作业调度 static int[]原创 2020-07-24 22:02:51 · 124 阅读 · 0 评论 -
(回溯法)图的n着色问题
public class Coloring { static int n, // 图的顶点数 m; // 可用的颜色数 static boolean[][] a; // 图的邻接矩阵 static int[] x; // 当前解 static long sum; // 当前已找到的可m着色的方案数 public static long mColoring(int mm) { m = mm; sum =原创 2020-07-24 22:01:31 · 659 阅读 · 0 评论 -
(迭代回溯)n皇后问题
public class NQueen2 { static int n; // 皇后个数 static int[] x; // 当前解 static long sum; // 当前已找到的可行方案数 public static long nQueen(int nn) { n = nn; sum = 0; x = new int[n + 1]; for (int i = 0; i < n; i++) x[i原创 2020-07-24 21:58:25 · 252 阅读 · 0 评论 -
(回溯法)递归解决n皇后问题
public class NQueen1 { static int n; // 皇后个数 static int[] x; // 当前解 static long sum; // 当前已找到的可行方案数 public static long nQueen(int nn) { n = nn; sum = 0; x = new int[n + 1]; for (int i = 0; i < n; i++) x[i原创 2020-07-24 21:57:04 · 384 阅读 · 0 评论 -
(递归和分治)合并排序
public class MergeSort { static Comparable b[]; /** * 递归方式 * @param a * @param left * @param right */ public static void mergeSort(Comparable a[], int left, int right) { if (left < right) { int i原创 2020-07-24 21:55:28 · 315 阅读 · 0 评论 -
(递归和分治)快速排序
public class QuickSort { static Comparable[] a; public static void quickSort(int p, int r) { if (p < r) { int q = partition(p,r); quickSort(p,q - 1); quickSort(q + 1,r); } } private st原创 2020-07-24 21:52:44 · 119 阅读 · 0 评论 -
(动态规划)矩阵连乘问题
public class MatrixQuestion { static int n; // 矩阵数量 public static void MatriaxChain(int[] p, int[][] m, int[][] s) { for (int i = 0; i <= n; i++) { m[i][i] = 0; } for (int r = 2; r <= n; r++) { // 多少个矩阵相乘原创 2020-07-24 21:49:00 · 80 阅读 · 0 评论 -
(动态规划)电路布线问题
public class MNset { public static void mnset(int[] c, int[][] size) { int n = c.length - 1; for (int j = 0; j < c[1]; j++) { size[1][j] = 0; // 下面没有接线柱的时候,都为0 } for (int j = c[1]; j <= n; j++) {原创 2020-07-24 21:47:07 · 211 阅读 · 0 评论 -
最长公共子序列
public class LcsLength { static int[][] c; public static int lcsLength(char[] x, char[] y, int[][] b) { int m = x.length - 1; int n = y.length - 1; c = new int[m+1][n+1]; for(int i = 1; i <= m; i++) {原创 2020-07-24 21:43:22 · 83 阅读 · 1 评论