Created
September 20, 2015 07:41
-
-
Save luckypapa/1f98d924d3f3fc8d283e to your computer and use it in GitHub Desktop.
solution of TRIANGLEPATH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://algospot.com/judge/problem/read/TRIANGLEPATH | |
#include <iostream> | |
#include <memory.h> | |
#include <algorithm> | |
using namespace std; | |
int triangle[101][101]; | |
int cache[101][101]; | |
int N; | |
int getMaxValue(int x, int y) { | |
if (x == N) { | |
return 0; | |
} | |
if (cache[x][y]) { | |
return cache[x][y]; | |
} | |
return cache[x][y] = | |
triangle[x][y] + max(getMaxValue(x+1, y), getMaxValue(x+1, y+1)); | |
} | |
int main(void) { | |
int T; | |
cin >> T; | |
while (T-- > 0) { | |
cin >> N; | |
for (int i = 0; i < N; i++) { | |
for (int j = 0; j < i+1; j++) { | |
cin >> triangle[i][j]; | |
} | |
} | |
memset(cache, 0, sizeof(cache)); | |
cout << getMaxValue(0, 0) << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment