1163 -- The Trianglehttp://poj.org/problem?id=1163
#include <iostream>
#define x first
#define y second
using namespace std;
typedef long long ll;
int dp[128][128] = { 0 };
int a[128][128] = { 0 };
int main() {
// system("chcp 65001");
cin.tie(0);
cout.tie(0);
freopen("C:/Users/zhaochen/Desktop/input.txt", "r", stdin);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++) {
dp[n][i] = a[n][i];
}
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j <= i; j++) {
dp[i][j] = a[i][j] + max(dp[i + 1][j], dp[i + 1][j + 1]);
}
}
cout << dp[1][1];
return 0;
}