关于最短路问题!!

cxygoo 2002-05-02 02:55:30
有那位高手能用C帮我解决这个问题,先谢过了!
...全文
113 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
crazy_lazy_pig 2002-05-02
  • 打赏
  • 举报
回复
真想帮你,可是没时间,给你一个MAPLE代码,先研究一下吧:
Dijkstra:=proc(G,v)
> local Tree,nodes,preV,Dj,V,V_G,
> i,k,temp2,temp1,tempE,ename,head;
>
> if (not type(G,GRAPH)) then
> error "the parameter must be type of GRAPH"
> fi:
>
> nodes:=nops(vertices(G)):
> new(Tree):
> V:=[]:
> V_G:=convert(vertices(G) minus {v},list):
> preV:=table([seq(V_G[i]=v,i=1..nodes-1)]):
>
> Dj:=table([seq(V_G[i]=infinity,i=1..nodes-1)]):
> for i to nodes-1 do
> if(edges([v,V_G[i]],G)<>{}) then
> Dj[V_G[i]]:=eweight(op(edges([v,V_G[i]],G)),G):print(Dj);
> end if:
> end do:
>
> for k to nodes-1 do
> temp1:=Dj[V_G[1]];temp2:=1;
> for i to nops(V_G) do
> if (temp1<Dj[V_G[i]]) then
> temp1:=Dj[V_G[i]]:
> temp2:=i:
> end if:
> end do:
> V:=[op(V),V_G[temp2]]:
> V_G:=[seq(V_G[i],i=1..temp2-1),seq(V_G[i],i=temp2+1..nops(V_G))]:
> for i to nops(V_G) do
> tempE:=edges([v,V_G[i]],G):
> if (tempE<>{}) then
> if(temp1+eweight(op(tempE),G)<Dj[V_G[i]]) then
> Dj[V_G[i]]:=temp1+eweight(op(tempE),G):
> preV[V_G[i]]:=V_G[temp2]:
> end if
> end if:
> end do:
> if(nargs=3 and ({args[3]} minus vertices(G))={})then
> if(V[nops(V)]=args[3])then break fi
> end if:
> end do:
> addvertex(vertices(G),Tree):
> if (nargs>=3) then
> if (({args[3]} minus vertices(G))={}) then
> head:=args[3]:
> while(head<>v)do
> addedge({head,preV[head]},Tree):
> head:=preV[head]:
> end do:
> return Tree:
> elif (nargs=4) then
> assign(args[4]=op(Dj)):
> else
> assign(args[3]=op(Dj));
> end if:
> end if:
> for i from nodes-1 by -1 to 1 do
> ename:=op(edges([preV[V[i]],V[i]],G)):
> addedge({V[i],preV[V[i]]},names=ename,weights=eweight(ename,G),Tree):
> end do:
> return Tree:
> end proc:
cxygoo 2002-05-02
  • 打赏
  • 举报
回复
随便说个事例,用图来编就可以了
angel_mine 2002-05-02
  • 打赏
  • 举报
回复
说明白一点?

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧