日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

floyd

發布時間:2025/1/21 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 floyd 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

flyod

1:詳解

  • 0
  • 0
    • 0,此時 【0】【0】 不比【0】【0】 + 【0】【0】 小,所以不變
    • 1,此時【0】【1】 和【0】【0】 和 【0】【1】比較
      • 【0】【1】 = 5 【1】【1】 = 0,不比他小
    • 2,此時【0】【2】 【0】【0】+【0】【2】 ,由于權值沒有負數,所以 K = 0 沒有意義
  • 1
    • 0
      • 0,此時【0】【0】 和 【0】【1】 + 【1】【0】比較,無意義
      • 1,此時【0】【1】 和 【0】【1】 + 【1】【1】 比較,無意義
      • 2,此時【0】【2】 和 【0】【2】 + 【2】【2】比較,無意義
    • 1
      • 0,此時【1】【0】 和【1】【1】 + 【1】【0】 比較,無意義
      • 1,此時【1】【1】 和【1】【1】 + 【1】【1】比較,無意義
      • 2,此時【1】【2】 和【1】【1】 + 【1】【2】 比較,無意義
      • 3,此時【1】【3】 和【1】【1】 + 【1】【3】 比較,無意義
    • 2
      • 0,此時【2】【0】 和 【2】【1】 + 【1】【0】 比較,不比她小,所以不變
#include <bits/stdc++.h>using namespace std;// Number of vertices in the graph #define V 4/* Define Infinite as a large enough value.This value will be used for vertices not connected to each other */ #define INF 99999// A function to print the solution matrix void printSolution(int dist[][V]);// Solves the all-pairs shortest path // problem using Floyd Warshall algorithm void floydWarshall(int graph[][V]) {/* dist[][] will be the output matrixthat will finally have the shortestdistances between every pair of vertices */int dist[V][V], i, j, k;/* Initialize the solution matrix sameas input graph matrix. Or we can saythe initial values of shortest distancesare based on shortest paths consideringno intermediate vertex. */for (i = 0; i < V; i++)for (j = 0; j < V; j++)dist[i][j] = graph[i][j];/* Add all vertices one by one tothe set of intermediate vertices.---> Before start of an iteration,we have shortest distances between allpairs of vertices such that theshortest distances consider only thevertices in set {0, 1, 2, .. k-1} asintermediate vertices.----> After the end of an iteration,vertex no. k is added to the set ofintermediate vertices and the set becomes {0, 1, 2, ..k} */for (k = 0; k < V; k++) {// Pick all vertices as source one by onefor (i = 0; i < V; i++) {// Pick all vertices as destination for the// above picked sourcefor (j = 0; j < V; j++) {// If vertex k is on the shortest path from// i to j, then update the value of// dist[i][j]if (dist[i][j] > (dist[i][k] + dist[k][j])&& (dist[k][j] != INF&& dist[i][k] != INF))dist[i][j] = dist[i][k] + dist[k][j];}}}// Print the shortest distance matrixprintSolution(dist); }

總結

以上是生活随笔為你收集整理的floyd的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。