| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 356 人关注过本帖
标题:一段程序的分析
取消只看楼主 加入收藏
shengxp119
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-5-16
收藏
 问题点数:0 回复次数:1 
一段程序的分析
//帮忙做一段程序的分析
//程序如下:
#define MAXNUMBER 10
#define MAXLENGTH 5000
int weight[MAXNUMBER][MAXNUMBER];
int findshortestpath(int *includearray,int i,int includenumber)
{
int totalweight,value;
int t,j,k=2,point=2,minlength=MAXLENGTH;
int select[MAXNUMBER][MAXNUMBER];
if(includenumber==1)
return(weight[1][*(includearray+i)]);
value=*(includearray+i);
for(j=2;j<=includenumber+1;j++)
{
k=2;
for(t=2;t<=includenumber+1;t++)
if(t!=i)
select[j][k++]=*(includearray+t);
if(j<i)
{
totalweight=findshortestpath(select[j],j,includenumber-1);
totalweight=totalweight+weight[select[j][j]][value];
}
else if(j>i)
{
totalweight=findshortestpath(select[j],j-1,includenumber-1);
totalweight=totalweight+weight[select[j][j-1]][value];
}
else if(j==i)
continue;
if(totalweight<minlength)
{
point=j;
minlength=totalweight;
}
}
for(j=2;j<includenumber+1;j++)
*(includearray+j)=select[point][j];
*(includearray+j)=value;
return(minlength);
}
main()
{
int number,minlenght=MAXLENGTH;
int i,j,point=1,totalweight;
int vallagename[MAXNUMBER][MAXNUMBER];
printf("\nplease input the number of the vallage:");
scanf("%d",&number);
if(number<=0)
{
printf("input error!");
return;
}
for(i=1;i<=number;i++)
for(j=1;j<=number;j++)
{
printf("the weight[%d][%d]:",i,j);
if(i!=j)
scanf("%d",&weight[i][j]);
else
printf("0\n");
vallagename[i][j]=j;
}
for(i=1;i<=number;i++)
for(j=1;j<=number;j++)
{
printf("%d ",weight[i][j]);
if(j==number)
printf("\n");
}
for(i=1;i<=number;i++)
for(j=1;j<=number;j++)
{
if(j==1)
printf("\n");
printf("%d ",vallagename[i][j]);
}
for(i=2;i<=number;i++)
{
totalweight=findshortestpath(vallagename[i],i,number-1);
totalweight+=weight[i][1];
if(totalweight<minlenght)
{
point=i;
minlenght=totalweight;
}
printf("\nthe shortest path is:1");
for(i=2;i<=number;i++)
printf("--->%d",vallagename[point][i]);
printf("--->1");
printf("\n the weight is %d",minlenght);
getch();
}
}
//结果可以发送到我的邮箱里:shengxp119@21cn.com
//谢谢啊
2006-05-16 14:30
shengxp119
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-5-16
收藏
得分:0 
我是初学者
上面那段程序我看不懂
有谁能帮我把程序加上注释~~~
帮帮忙啊
2006-05-16 21:42
快速回复:一段程序的分析
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040761 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved