Floyd algorithm, floyd

Source: Internet
Author: User

Floyd algorithm, floyd

Floyd algorithm

The Floyd algorithm, also known as the insertion method, is an algorithm used to find the shortest path between multiple source points in a given weighted graph. The algorithm name is named after one of the founders, the winner of the Turing Award in 1978, and the professor of computer science at Stanford University, Robert freuch.

Note: As you can see from the following exercises, many questions do not directly ask you how to find the shortest path, but require you to use the Dynamic Planning Idea of floyd to solve problems similar to floyd.

Floyd algorithm can calculateEdge Weight is not negative.. The following is an algorithm template.

<Span style = "font-size: 18px;" >#include <cstdio> using namespace std; # define INF 1e9const int maxn = 100 + 10; int n, m; // points, number of sides, points from 0 to n-1 No. int dist [maxn] [maxn]; // records the distance matrix int path [maxn] [maxn]; // path [I] [j] = x indicates that the first Vertex on the path from I to j (except I) is x. void init () {for (int I = 0; I <n; I ++) for (int j = 0; j <n; j ++) {dist [I] [j] = I = j? 0: INF; // In fact, here d [I] [j] should also use the path [I] [j] = j ;} // read other dist [I] [j] values} void floyd () {for (int k = 0; k <n; k ++) for (int I = 0; I <n; I ++) for (int j = 0; j <n; j ++) if (dist [I] [k] <INF & dist [k] [j] <INF) {if (dist [I] [j]> dist [I] [k] + dist [k] [j]) {dist [I] [j] = dist [I] [k] + dist [k] [j]; path [I] [j] = path [I] [k];} else if (dist [I] [j] = dist [I] [k] + dist [k] [j] & path [I] [j]> path [I] [k]) {path [I] [j] = path [I] [k]; // The final path in the path contains the path with the smallest Lexicographic Order }}} int main () {// read n and m init (); // read m edge floyd (); // output the shortest path from return 0;} </span>


Floyd algorithm application

HDU 1690Bus System (Floyd): simple application.Solution report!

POJ 2240 Arbitrage (Floyd): The DP concept of Floyd.Solution report!

HDU 1385 Minimum Transport Cost (Minimum path of Floyd + print Lexicographic Order): path with the smallest deformation and output Lexicographic Order.Solution report!

POJ 2263 Heavy Cargo (Floyd deformation): floyd deformation.Solution report!

POJ 1847 Tram (Floyd): the shortest path of a dynamic graph.Solution report!

POJ 1125 Stockbroker Grapevine (Floyd): simple application of Floyd.Solution report!

POJ 3615Cow Hurdles (Folyd deformation): the minimum value in the maximum value.Solution report!

POJ 3660Cow Contest (Floyd transfer closure): The transfer closure problem.Solution report!

POJ 1975 Median Weight Bead (Floyd passed closure): passed closure.Solution report!

POJ 2570 Fiber Network (Floyd transfer closure + state compression): State compression + transfer closure.Solution report!

HDU 4034 Graph (Floyd deformation): The necessary edge of the shortest path of a directed Graph.Solution report!

HDU 3665 Seaside (simple Floyd ):Solution report!

HDU 2807The Shortest Path (matrix multiplication + Floyd ):Solution report!

HDU 1869 six-degree separation (simple Floyd ):Solution report!

HDU 1245 Saving James Bond (Floyd): simple Floyd, which requires some analysis.Solution report!

POJ 2502 Subway (Floyd single-source shortest path): simple application.Solution report!

 


Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.