# include<iostream>
#include<cstdio>
using namespace std;
const int maxn=100;
int dp[maxn][maxn],a[maxn][maxn];
int max(int x,int y)
{
return ((x>y)?x:y);
}
int main()
{
int n;
while(cin>>n)
{
for(int i=0;i<n;i++)
for(int j=0;j<=i;j++)
cin>>a[i][j];
for(int i=0;i<n-1;i++)
dp[n-1][i]=a[n-1][i];
for(int i=n-2;i>=0;i--)
for(int j=0;j<n-1;j++)
dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+a[i][j]; // 递推 状态方程
cout<<dp[0][0]<<endl;
}
return 0;
}
The Triangle
最新推荐文章于 2020-05-03 16:51:48 发布