C++ 代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 510;
int a[maxn][maxn];
int main()
{
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 = n - 1; i; i -- )
{
for (int j = 1; j <= i; j ++ )
{
a[i][j] += max(a[i + 1][j], a[i + 1][j + 1]);
}
}
cout << a[1][1] << endl;
return 0;
}