Openjudge Leasing of Yachts

Source: Internet
Author: User
Tags time limit
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

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.