`
t225com
  • 浏览: 658609 次
文章分类
社区版块
存档分类
最新评论

1436 Renting Boats

 
阅读更多

Accept: 225Submit: 485
Time Limit: 1000 mSecMemory Limit : 32768 KB

Problem Description

Yangtse Rive Barge Club has set up n barge hiring stops numbered 1, 2, … , n along the Changjiang River. Passengers can hire barges from any of these stops, and return the barges to one of the stops afterward. The rent for an barge from stop i to stop j is r(i,j) (1<=i,j<=n). Your task is to design an algorithm to minimize the rent of hiring barges when you traveling from stop 1 to stop n.

Input

There are multiple test cases. The first line of each case contains an integer n indicating the number of the stops (n<=200). The following n-1 lines are the rent between any two stops. The ith following line contains n-i integers indicating r(i,j) (i < j <= n).

Output

For each case, output one line representing the minimal rent.

Sample Input

3
5 15
7

Sample Output

12
思路:
题目的意思就是求从停泊点1到n的最少费用
就是求单点源最短路径的问题, 用dijkstra算法
如果存在<Vi,Vj>则map[Vi][Vj]=权值(这里就是vi->vj的费用)
如果不存在初始化为INF(无穷大)
dist[i]数组用来存放源点1到点i的最少费用,
s[i]用来标记源点1到点i的最少费用是否算出
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics