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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

C++——《算法分析》实验肆——单源最短路径问题

發布時間:2025/3/15 c/c++ 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++——《算法分析》实验肆——单源最短路径问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

實驗目的
1、理解分支限界法的剪枝搜索策略;
2、 掌握分支限界法的算法柜架;
3、 掌握分支限界法的算法步驟;
4、 通過應用范例學習動態規劃算法的設計技巧與策略;
源程序

#include <iostream> #include<vector> #include<queue> using namespace std; typedef struct ArcCell {int u;int info;ArcCell(int a, int b){u = a;info = b;} }ArcCell, AdjMaxtrix[100][100]; typedef struct {int data;int length; }VerType; typedef struct {VerType vexs[100];vector<ArcCell>arcs[1001];int vexnum;int arcnum; }Graph; Graph G; queue<int> q; int main() {int m, n, t;cout << "輸入頂點個數和弧邊個數:" << endl;cin >> G.vexnum >> G.arcnum;for (int i = 1; i <= G.vexnum; i++){G.vexs[i].data = i;G.vexs[i].length = 10000;}cout << "輸入弧及權重:" << endl;for (int i = 1; i <= G.arcnum; i++){cin >> m >> n >> t;G.arcs[m].push_back({ n,t });}G.vexs[1].length = 0;q.push(G.vexs[1].data);while (!q.empty()){int t = q.front();for (int i = 0; i < G.arcs[t].size(); i++){int k = G.arcs[t][i].u;if (G.vexs[t].length + G.arcs[t][i].info <= G.vexs[k].length){G.vexs[k].length = G.vexs[t].length + G.arcs[t][i].info;q.push(G.vexs[k].data);}}q.pop();}for (int i = 1; i <= G.vexnum; i++) cout << G.vexs[i].data << "——" << G.vexs[i].length << endl;return 0; }

實驗結果:

總結

以上是生活随笔為你收集整理的C++——《算法分析》实验肆——单源最短路径问题的全部內容,希望文章能夠幫你解決所遇到的問題。

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