IOI '94 - Haninge, Sweden
The Triangle
7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1)
Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base.
- Each step can go either diagonally down to the left or diagonally down to the right.
- The number of rows in the triangle is > 1 but ≤ 100.
- The numbers in the triangle, all integers, are between 0 and 99 inclusive.
Input Format
The first line of input contains the integer n, the number of lines in the triangle. The remaining n lines will contain the values of the triangle.
Output Format
The output should contain one integer, the highest possible sum.
Sample Input
5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
Sample Output
30
All Submissions
Best Solutions
Point Value: 7
Time Limit: 2.00s
Memory Limit: 10.140625M
Added: Dec 25, 2013
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
I'm fairly sure your algorithm is fine, though.
*If I'm incorrect on this point I'm sure someone will correct me.
The ratio of rows to memory was exponential.
10 rows took around 5MB
15 rows took around 15MB
while 20 took around 280MB