Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这是floyed算法的一种标准错误写法

Posted by fanhqme at 2009-04-11 20:59:35 on Problem 1125
In Reply To:无语了,wa了n次,真不知道哪地方出问题了!!! Posted by:fuliang at 2009-04-10 23:03:18
请注意floyed算法的本质是动态规划!
定义f(i,j,k)表示只用第0~i个点从j走到k所用的最短路程。
f(i,j,k)=min(f(i-1,j,k),f(i-1,j,i)+f(i-1,i,k))
所以应该是
for(int i = 0; i < sz; i++)
		for(int j = 0; j < sz; j++)
			for(int k = 0; k < sz; k++){
				int t_dis = distances[j][i] + distances[i][k];
				if(distances[j][k] > t_dis)
					distances[j][k] = t_dis;
			}
很多人没有弄懂floyed的本质就开始背“三个for”的代码,所以会出现这种标准错误答案

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator