p150.txt 960 B

123456789101112131415161718192021222324252627
  1. Algorithm:
  2. Classic dynamic programming problem:
  3. Top down approach:
  4. Starting with the top, we find the sum, and remember it
  5. Recusively find the smallest sum for all triangles at that index
  6. Then loop through all items in the row below by passing them the index and the sum.
  7. Continue until there are no more triangles
  8. The functions we need:
  9. Func1 search-sub-triangles Index Sum:
  10. This function recursively finds the smallest triangle with the index as the point
  11. Func2 get-sub-triangle-sum index, row, sum:
  12. Will sum the row, and subtract it from the sum
  13. Since we are going to be doing a lot of index recalling, we should use a triangle array, nt list.
  14. Can we make any assumptions as we try to find a small triangle? I suppose not since we don't know much about the local changes....
  15. Note that indexing over the entire large triangle might take a little too long... We should use sub-triangles instead