最短路径(动态规划)

#include
#include
#include "stack"
#include "iostream"
using namespace std;
#define x 9999
#define max 9999
int dist[10];//记录最短路径为多少
int path[10];//记录最短路径


void fpath(int a[][10]);
int froute(int a[][10]);

void main()
{
	stack st;
     int i,m;
     int a[10][10]={
     {x,4,2,3,x,x,x,x,x,x},
	 {x,x,x,x,10,9,x,x,x,x},
     {x,x,x,x,6,7,10,x,x,x},
     {x,x,x,x,x,3,8,x,x,x},
     {x,x,x,x,x,x,x,4,8,x},
     {x,x,x,x,x,x,x,9,6,x},
     {x,x,x,x,x,x,x,5,4,x},
     {x,x,x,x,x,x,x,x,x,8},
     {x,x,x,x,x,x,x,x,x,4},
     {x,x,x,x,x,x,x,x,x,x}};
     
	 fpath(a);
     printf("最短路径大小为:  %d\n",dist[9]);

	 int end =9;
	 while(end>0)
	 {
		st.push(end+1);
		end =path[end];
	 }
	 st.push(1);
	 while(!st.empty())
	 {
		cout<

你可能感兴趣的:(算法合集)