![basic number theory codechef basic number theory codechef](https://cdn.codechef.com/sites/all/themes/abessive/cc-logo.png)
Then for each of the numbers there calculate what is the maximum value they can achieve going down, which is basically the numbers themselves plus the max out of the two numbers below. There’s a rather clever way to solve this in linear time: start with the second to last row.
![basic number theory codechef basic number theory codechef](https://codechef-blog.s3.amazonaws.com/wp-content/uploads/2021/04/19171041/Free-Classes-Blog-13-1024x536.jpg)
However, as the input size grows the brute force approach stops working, as the number of possible paths you’ll need to calculate grows exponentially. Solving this problem with a brute force approach is possible, especially if the input is small, as in this case. Each test case starts with the number of lines which is followed by their content.įor each test case write the determined value in a separate line. In the first line integer n – the number of test cases (equal to about 1000). The number of rows is strictly positive, but less than 100Īll numbers are positive integers between O and 99. On each path the next number is located on the row below, more precisely either directly below or below and one place to the right Develop a program which will compute the largest of the sums of numbers that appear on the paths starting from the top towards the base, so that: Let’s consider a triangle of numbers in which a number appears in the first line, two numbers appear in the second line, three in the third line, etc.
![basic number theory codechef basic number theory codechef](https://i.ytimg.com/vi/gREDFgHL9m4/hqdefault.jpg)
The problem below is a classic, although I wouldn’t necessarily classify it as “easy” as the guys from CodeChef did. Still practicing for Facebook Hacker Cup 2013.