/* For a long time did not do the problem of graph theory, review. ---------------------------------------------------------Shortest-circuiting (Floyd-warshall algorithm) dynamic programming between any two points: dp[k][i][j]:= node I can reach the shortest path of the J-node through a node numbered 1,2...K. The use of 1,2...K nodes, can be divided into the following two scenarios to discuss: (1) I to j t
The Floyd-warshall algorithm is a powerful weapon to solve the shortest path of any two points. It also applies to cases where there are negative edges.DP idea, assuming that only the first k points are used, the shortest distance from I to J is d[k][i][j]Then, the k+1 points can be used in two different situations.The shortest ①i to J is used for the first k+1 (d[k+1][i][j] = d[k][i][j])The shortest circui
, due to the update of 3, so recursively update all the shortest path from 1 to 3 points, 3 of the point is 1, and min (1->1 ) does not require an update to remain at 0.Article II, 1->4->3Min (1->3) is 4, and Min (1->4->3) is 10, so no update is required. So the end result is:
1
2
3
4
1
0
3
4
1
2
5
0
1
6
3
4
7
0
5
4
7
2
3
Floyd-warshall can efficiently solve the problem of multi-source shortest path in graph theory. Its essence is a dynamic planning of the label method. Because of this, the implementation of this algorithm is very valuable, that is, its conciseness. So many people will use it when seeking the most single-source short circuit, rather than Dijkstra or Bellman-Ford, which is more efficient but less annoying (of
Idea: feel a bit like violence ah, anyway I feel very violent, such as beg d[i][j], use this method to ask, directly consider will not go through a point K (k is any point), and finally get the minimum valueLook at the code#include #include#include#include#includestring.h>#include#include#include#includeSet>#include#includetypedefLong Longll;using namespacestd;Constll mod=1e9+7;Const intmaxn=1e3+Ten;Const intmaxk= -+Ten;Const intmaxx=1e4+Ten;Constll maxe= ++Ten;#defineINF 0x3f3f3f3f3f3fintV,e;ll
The Floyd-warshall algorithm is used to locate the shortest distance between each point. It needs to store edges using an adjacent matrix. This algorithm obtains the optimal path by considering the best sub-path.
Note that the path of an edge is not necessarily the best path.
Start with any single-side path. The distance between all two points is the edge weigh
updated. It is necessary to update the shortest path from 1 to 2 points, and 2 to 3. MIN (1->3) is now 9. Min (1->4->2->3) is 4, so min (1->3) is updated to 4. Due to the update of 3. Therefore recursive update all from 1 to 3 the shortest path of the point, 3 of the point is 1, and min (1->1) does not need to update to remain 0.Article II, 1->4->3Min (1->3) is 4, while min (1->4->3) is 10. So there is no need to update.So finally the result is:
?
1
2
3
4
The froyd-warshall algorithm is used to solve the shortest distance between all vertices. The weight value can be a negative value, but cannot have a negative ring. The time complexity is O (n ^ 3 ).
The idea of this algorithm is,
Step 1: All the shortest paths from I to J are the weights between I and j (if they are not connected, they are set to a max value)
St
Evaluate the closure of a linkAlgorithmThe time complexity is the fourth power of N. This algorithm is the third power of N, so warshall won the Tulin award.
# Include # Include # Include
Void main (){Int n_dim = 0;Cout Cin> n_dim;
Char ** array = new char * [n_dim]; // The following figure shows how to dynamically create an n_dim * n_dim array.Char ch; // another article about Dynamic ArrayArticle
of the data structure diagram, thinking with a double linked list with a variety of conditions to resolve, found too complex, and then search on the Internet, here provides a map to solve the floyed algorithm, links are as follows:
http://blog.csdn.net/arcsinsin/article/details/11267755
In view of this , these days hurriedly went to see the next part of the figure, just looked at the Dijkstra single source point to all the shortest path
How to Implement the shortest path algorithm in JAVA: dijela Algorithm
The shortest path is a classic algorithm in graph theory. It is designed to find the shortest path between two nodes in the graph, the most common algorithms are Dijkstra algorithm, SPFA
sorted sequences, which is used to hold the merged sequence,
set two pointers, The initial position is the starting position of two sorted sequences,
Compare the elements pointed to by two pointers, select a relatively small element into the merge space, And move the pointer to the next position;
Repeat step 3 until a pointer reaches the end of the sequence;
Copies all the remaining elements of another sequence directly to the end of the merge sequence.
a
sorted sequences, which is used to hold the merged sequence,
set two pointers, The initial position is the starting position of two sorted sequences,
Compare the elements pointed to by two pointers, select a relatively small element into the merge space, And move the pointer to the next position;
Repeat step 3 until a pointer reaches the end of the sequence;
Copies all the remaining elements of another sequence directly to the end of the merge sequence.
a
This is a creation in
Article, where the information may have evolved or changed.
Common internal sorting algorithms are: Insert sort, hill sort, select sort, bubble sort, merge sort, quick sort, heap sort, cardinality sort, etc. Summarize with a picture:
Merge sort (English: merge sort, or mergesort) is an efficient sorting algorithm that creates an O (n log n) on a merge operation. It was first presented by John von Neumann in 1945. The
Java Algorithm interview questions: What are the methods for sorting? List. Use JAVA to implement a fast sorting. Select bubble quick set to sort by at least four methods, java Algorithm
Package com. swift; import java. util. arra
Java poker licensing Algorithm Implementation and java poker Algorithm
Java poker licensing Algorithm Implementation Code: http://www.zuidaima.com/share/1550463274224640.htm
Two Methods: A. Poker licensing
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.