The question of renting a yacht
View Submit Statistics Questions
Total time limit: 10000ms single test point time limit: 1000ms memory limit: 128000kB
Describe
The Yangtze River Amusement Club in the Yangtze River set up n yacht rental stations, tourists can use yachts in these yacht rental stations, and in the downstream of any yacht rental station return yacht, yacht rental Station I to J between the rent is rent (i,j), which 1<=i<j=n.
Design requirements: For a given yacht rental station I to the yacht rental station J rent between R (i,j), 1<=i<=j, programming calculation of the yacht rental Station 1 to the yacht rental station n the minimum rent required.
The input consists of multiple sets of test data. The first line has a positive integer n, which means n a yacht rental station. Next n-1 the act of rent. Such as:
3
5 (Rental Station 1 to rental station 2 rent) 15 (Rental Station 1 to rental Station 3 rent)
7 (Rental of 2 to rental Station 3 rent)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
int main ()
{
int n;
int a[201];
int t;
memset (a,0,sizeof (int) *201);
while (Cin>>n)
{to
(int i = 1; i < n; i++)
{for
(int j = 1; j < n-i+1; j)
{
cin>>t;
if (a[i+j]==0)
a[i+j]=a[i]+t;
else if (a[i]+t <a[i+j]) a[i+j]=a[i]+t
}
cout << a[n]<<endl;
}
return 0;
}
Output:
12 (minimum rent)
Input
There are 1 positive integers n (n<=200) in line 1th of the file, indicating that there are n yacht rental stations.
The next n-1 line is R (i,j), 1<=i
Output
At the end of the program, the minimum rental output is calculated from the yacht rental station L to the yacht rental station N.
Sample input
3
5 15
7
Sample output
12