daily pastebin goal


a guest Jun 22nd, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static int maxPath(int[][] a, int row, int col) {
  2.     if(row<rows) { //while still more rows
  3.         if(max[row][col]>0) //we've found this subtree's max path before
  4.             return max[row][col]; //get it
  5.         else { //we've yet to find this subtree's max path
  6.             //set the max path for this subtree with the current value plus the
  7.             //greater of the left subtree's max path and the right subtree's max path
  8.             max[row][col]=a[row][col]+max(maxPath(a, row+1, col), maxPath(a, row+1, col+1));
  9.             return max[row][col]; //return the result
  10.         }
  11.     }
  12.     return 0; //end of triangle
  13. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand