/*
    ID:chenjiong
    PROG:numtri
    LANG:C++
*/

#include <stdio.h>
#include <string.h>

const int MAXN = 1005;

int N;
int mat[MAXN][MAXN];
int dp[MAXN][MAXN];
int ans;

int max(int x,int y)
{
    return x > y ? x : y;
}

void solve()
{
    dp[0][0] = mat[0][0];

    int i,j;
    for ( i = 1; i < N; i++)
    {
        dp[i][0] = dp[i - 1][0] + mat[i][0];
        dp[i][i] = dp[i - 1][i - 1] + mat[i][i];
    }
    ans = max(dp[N - 1][0],dp[N - 1][N - 1]);
    for ( i = 2; i < N; i++)
    {
        for ( j = 1; j < i; j++)
        {
            dp[i][j] = max(dp[i - 1][j - 1],dp[i - 1][j]) + mat[i][j];
            if ( i == N - 1 )
            {
                if ( dp[i][j] > ans )
                    ans = dp[i][j];
            }
        }
    }
}

int main()
{
    freopen("numtri.in","r",stdin);
    freopen("numtri.out","w",stdout);

    int i,j;
    scanf("%d",&N);
    for ( i = 0; i < N; i++)
        for ( j = 0; j <= i; j++)
            scanf("%d",&mat[i][j]);

    solve();

    printf("%d\n",ans);
    return 0;
}
        

        

 

posted on 2012-10-25 21:14  Sinker  阅读(122)  评论(0编辑  收藏  举报