From an algorithm point of view (no code), start from the bottom and work your way up. You know that on the penultimate row, the biggest value you can get on the "6" is 6+5, the biggest value you can get on the "4" is 4+7, and the biggest value you can get on the "9" is 9+7. Move up a row; the biggest value you can get on the "2" is the same whether you chose 2+6+5 or 2+4+7. The biggest on the "4" is 4+9+7. From the peak "1", the biggest you can get is from the 1+4+9+7.
So you have to visit each node once, but you never need to recurse or try every path.
edit: whoops, I described finding the maximum; thanks LanX. The idea is the same, just pick the smallest each time /edit
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.