#include<iostream>
using namespace std;
const int N=1e3+5;
int n;
int f[N][N],a[N][N],ans;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout<<fixed;
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++)
for(int j=1;j<=n;j++)
f[i][j]=max(f[i-1][j-1]+a[i][j],f[i-1][j]+a[i][j]);
for(int i=1;i<=n;i++)ans=max(ans,f[n][i]);
cout<<ans<<endl;
return 0;
}
//coder:Iictiw
//date:23/05/23
标签:数字,第一天,int,sync,三角形,DP
From: https://www.cnblogs.com/Iictiw/p/17426425.html