1624: [Usaco2008 Open] Clear and Present Danger Treasure Trail

Source: Internet
Author: User

1624: [Usaco2008 Open] Clear and Present Danger Treasure Trail Time limit:5 Sec Memory limit:64 MB
submit:377 solved:269
[Submit] [Status] Description farmer John is driving a small boat sailing on the Neuleby Sea. There are N (1≤n≤100) Islands at sea, numbered 1 to N. John departs from small island 1th and finally arrives at Island N.  A treasure map says that if the island on which he traveled was followed by a sequence of Ai,a2,...,am (2≤m≤10000) (not necessarily adjacent), he would eventually find the ancient treasure. However, due to the Newlerby there are pirates infested. John knew the probability of piracy on the route between any of the two islands, and he described it with a danger index Dij (0≤dij≤100000). He wants his treasure hunt to go through the lowest risk index of the route. So, what is the smallest risk index, if you find the treasure? Input line 1th enters N and M, and the M line is followed by an integer representing a sequence, followed by a nxn square that represents the risk index of the route between the 22 islands. Data Assurance dij=dji,dii=0. Output the smallest risk index and. Sample Input3 4
1
2
1
3
0 5 1
5 0 2
1 2 0

INPUT DETAILS:

There is 3 islands and the treasure map requires Farmer John to
Visit a sequence of 4 islands in Order:island 1, Island 2, Island
1 again, and finally Island 3. The danger ratings of the paths are
Given:the paths (1, 2); (2, 3); (3, 1) and the reverse paths have
Danger ratings of 5, 2, and 1, respectively.


Sample Output7

OUTPUT DETAILS:

He can get the treasure with a total danger of 7 by traveling in
The sequence of islands 1, 3, 2, 3, 1, and 3. The cow map ' s requirement
(1, 2, 1, and 3) are satisfied by the this route. We avoid the path
Between Islands 1 and 2 because it has a large danger rating.
HINT Source

Silver

The puzzle: At first glance the path of the request has to go through the following points, and then take the shortest path, scare me--until I see that must go through the following points in turn ... So there is nothing, first Floyd to make the shortest path between the points, and since the requirements must be ordered through and not necessarily adjacent, then directly accumulate the shortest way of each segment will accept * ^_^ * ... (Ps:floyd do not exclude a[i,k] or a[k,j] to zero condition, because there is no direct connection in this topic point, even if the actual appearance of 0, represents the true sense of the two point distance is zero, although I did not kneel, but still feel the best to pay attention to the point ... )

1 var2 I,j,k,m,n:longint;3 L:int64;4A:Array[0.. $,0.. $] ofInt64;5B:Array[0..20000] ofLongint;6 begin7 readln (n,m);8       fori:=1  toM Do9 readln (B[i]);Tenb[0]:=1; Oneb[m+1]:=N; A       fori:=1  toN Do -          begin -                forj:=1  toN Do the read (a[i,j]); - Readln; -          End; -       fork:=1  toN Do +           fori:=1  toN Do -              begin +                   if(i=k) Thencontinue; A                    forj:=1  toN Do at                       begin -                            if(I=J)or(K=J) Thencontinue; -                            if(A[i,k]+a[k,j]) <a[i,j] Thena[i,j]:=a[i,k]+A[k,j]; -                       End; -              End; -       fori:=0  toM Do inl:=l+a[b[i],b[i+1]]; - Writeln (l); to End. +                    

1624: [Usaco2008 Open] Clear and Present Danger Treasure Trail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.