街道问题 (动态规划)
街道问题 在下图中找出从左下角到右上角的最短路径,每步只能向右方或上方走。 package com.iflytek.dp;public class Street{private int[][][] s = {{{0, 5, 4, 6, 2},{0 ,3, 6, 3, 5},{0 ,4, 6, 3, 5},{0 ,3, 7, 4, 8}},{{0, 8, 2, 7}, {0, 7, 8, 6},{0, 4, 5, 3},...
三角数塔问题
1、三角数塔问题设有一个三角形的数塔,顶点为根结点,每个结点有一个整数值。从顶点出发,可以向左走或向右走,如图所示: 要求从根结点开始,请找出一条路径,使路径之和最大,只要输出路径的和。package com.iflytek.dp;public class TriangularTower{private int[][] matrix;private int high, width;...
最长非递减子串问题
package com.iflytek.dp;public class LongestNonDecrease {private int[] s;private int size;private int[][] dp;private LongestNonDecrease(int[] s){this.s = s;this.size = this.s.length;this.dp = new int[this.size][];for(int i = 0; i < this.size; i++){this.dp[i] = new int[this.size];}...
汉诺塔递归与非递归实现
package com.iflytek.hanluo;import java.util.Stack;public class HLTower {public static Stack<Node> stack = new Stack<Node>();public static void recursion(int count,Pillar pillarA, Pillar pillarC, Pillar pillarB){if(count == 1){System.out.println(pillarA.name + " -> " + pillarC.name);}else{...
N后问题
package com.iflytek.nqueue;public class Node {public int floor; public int[] flag;private int N;public Node(int floor, int N){this.floor = floor;this.N = N;this.flag = new int[N];}public Node deepCopy(){Node node = new Node(this.floor, this.N);for(int i = 0; i < this.N; i++)node...