#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAX = 501;
int num[MAX][MAX];
int maxvalue(vector<vector<int>> t) {
int value = -1;
num[0][0] = t[0][0];
for (int i = 1; i < t.size(); i++) {
for (int j = 0; j < t[i].size(); j++) {
if (j == 0)
num[i][j] = t[i][j] + num[i - 1][0];
else if (j == t[i].size() - 1)
num[i][j] = t[i][j] + num[i - 1][j - 1];
else
num[i][j] = max(t[i][j] + num[i - 1][j - 1], t[i][j] + num[i - 1][j]);
}
}
for (int j = 0; j < t[t.size() - 1].size(); j++)
value = max(value, num[t.size() - 1][j]);
return value;
}
int solution(vector<vector<int>> triangle) {
int answer = 0;
answer = maxvalue(triangle);
return answer;
}
프로그래머스