POJ 2760: Digital triangles

Source: Internet
Author: User

ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {int[] Trinumbers =New int[101] [101];//0-100 inside        int[] Trimaxs =New int[101] [101]; Scanner in=NewScanner (system.in); intNrow = In.nextint ();//Number of rows         for(inti=0;i<nrow;i++)//Line        {             for(intj=0;j<=i;j++)//in-line{Trinumbers[i][j]=In.nextint ();        }} in.close ();  for(inti = nrow-1;i>=0;i--)        {             for(intj=i;j>=0;j--)//in-line            {                if(nrow==i) trimaxs[i][j]= Trinumbers[i][j];//last line                ElseTrimaxs[i][j]= Math.max (Trimaxs[i+1][j], trimaxs[i+1][j+1]) +Trinumbers[i][j]; }} System.out.println (trimaxs[0][0]); }}

Topic:

Total time limit:
1000ms
Memory Limit:
65536kB
Describe
7
3 8
8 1 0
2 7 4 4
4 5 2) 6 5

(Fig. 1)

Figure 1 shows a number triangle. There are many different paths from the top of the triangle to the bottom. For each path, add up the number of paths above to get one and your task is to find the largest and.

Note: Each step on the path can only go from one number to the next, or to the number on the right or to the nearest left.
Input
the input line is an integer N (1 < n <= 100), giving the number of rows of the triangle. The following n lines give the number triangles. The number on the number triangle ranges between 0 and 100.
Output
outputs the maximum and.
Sample input
573 88 1 0 2 7 4 44 5 2 6 5
Sample output
30
Source
the questions translated from IOI 1994
Some summary:
This problem was adopted in the
Programming Guide. It adapts dynamic planning to solving the problem, which takes less space and time than the measure of recursion.
Although the algorithm was described clearly, I still got ' WA ' when first pubmitted my src.
After
I compared the standard answer with mine, I found then the standard one adds ten to the max boundary of the ARRA Y.
Well
, after checking, I find in the Circulation,i or J can be 101,so the max boundary must is no less than 101.
The result always goes back to
a careless
man ...

POJ 2760: Digital triangles

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.