赞
踩
最短路径问题(Shortest path problem):再不回退的前提下,找到A到F的最短路径
A到B1的最短路径为4,前序节点为A;
A到B2的最短路径为5,前序节点为A;
A到C1的最短路径,我们可以看出,只有B1可以到达C1,所以最短路径为4+2=6,前序节点为B1;
A到C2的最短路径,我们可以看出,B1和B2都可以到达C2,其中经过B1的最短路径为4+3=7,经过B2的最短路径为5+8=13,所以A到C2的最短路径为7,前序节点为B1。
依次类推,得出下面的信息。
动态规划的思想:
public static LinkedList<String> getByDP(HashMap<String, LinkedList<String>> routes, HashMap<String, LinkedList<Integer>> distances, String origin, String destination){
HashMap<String, Integer> short_distance = new HashMap
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。