Rokua P1359 Rental Yacht

Source: Internet
Author: User

Title Description

The Changjiang Yacht Club has set up n yacht Rental station 1,2,...,n on the Changjiang River. Guests can rent a yacht at these yacht rental stations and return the yacht at any of the downstream yacht rental stations. The rental for yacht rental station I to yacht Rental station J is R (I,j), 1<=i<=j<=n. Try to design an algorithm that calculates the minimum rent required from the yacht rental Station 1 to the yacht rental station N.

For a given yacht rental station I will rent a rental of R (i,j) between the yacht rental station J, 1<=i<j<=n, and calculate the minimum rent required from the yacht rental Station 1 to the yacht rental station N.

Ensure that no value exceeds 10^6 at any time during the calculation

Input/output format

Input format:

The input data is provided by the file. The 1th line of the file has 1 positive integer n (n<=200), indicating that there are n yacht rental stations. The next n-1 line is a semi-matrix R (i,j), 1<=i<j<=n.

Output format:

At the end of the program run, the calculated minimum rent from the yacht rental Station 1 to the yacht rental station n is output to the file.

Input and Output Sample input example # #:
35 157
Sample # # of output:
12

SPFA has a forward edge

#include <iostream>#include<cstring>#include<cstdio>#defineINF 0x7fffffff#defineMX 50010using namespacestd;structNode {intTo,next,dis;} E[MX];intHEAD[MX],DS[MX];BOOLVIS[MX];intN,i,j,k,tot;voidAddintUintVintW) {Tot++; E[tot].to=v; E[tot].next=Head[u]; Head[u]=tot; E[tot].dis=W;}voidSPFA (intN) {    intL=0, r=0, que[ .];  for(i=1; i<=k;++i) {Ds[i]=INF; Vis[i]=0; } R++; QUE[R]=N; Ds[n]=0; VIS[K]=1;  while(l<=r) {L++; inttop=Que[l]; Vis[top]=0;  for(i=head[top];i;i=E[i].next) {            intv=e[i].to; if(ds[v]>ds[top]+E[i].dis) {Ds[v]=ds[top]+E[i].dis; if(!Vis[v]) {Vis[v]=1; R++; QUE[R]=v; }            }        }    }}intMain () {intc,x=0, y=0; CIN>>K;  for(i=1; i<=k-1;++i) { for(j=i+1; j<=k;++j) {cin>>C;        Add (I,J,C); }} SPFA (1); cout<<ds[k];}

Rokua P1359 Rental Yacht

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.