Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. string filename = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\input.txt";
  2. int[,] inputTriangle = readInput(filename);
  3.  
  4. int posSolutions = (int)Math.Pow(2, inputTriangle.GetLength(0) - 1);
  5. int largestSum = 0;
  6. int tempSum, index;
  7.  
  8. for (int i = 0; i <= posSolutions; i++) {
  9.     tempSum = inputTriangle[0, 0];
  10.     index = 0;
  11.     for (int j = 0; j < inputTriangle.GetLength(0) - 1; j++) {         index = index + (i >> j & 1);
  12.         tempSum += inputTriangle[j + 1, index];
  13.     }
  14.     if (tempSum > largestSum) {
  15.         largestSum = tempSum;
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement