原题链接:
https://www.acwing.com/problem/content/900/
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
int s[505][505];
int main()
{
int n;
cin >> n;
cin >> s[0][0];
for( int i=1;i<n;i++ )
{
cin >> s[i][0];
s[i][0] += s[i-1][0] ;
for( int j=1;j<i;j++ )
{
cin >> s[i][j];
if( s[i-1][j-1] > s[i-1][j] ) s[i][j]+=s[i-1][j-1];
else s[i][j]+=s[i-1][j];
}
cin >> s[i][i];
s[i][i] += s[i-1][i-1];
}
int max=s[n-1][0];
for ( int i=0;i<n;i++ ) if( max < s[n-1][i] ) max=s[n-1][i];
cout << max;
}