2015/2/12
数塔。
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<climits>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define mod 10007
#define lson pos<<1,l,mid
#define sc(n) scanf("%d",&n)
#define rson pos<<1|1,mid+1,r
#define pr(n) printf("%d\n",n)
#define met(n,m) memset(n, m, sizeof(n))
#define F(x,y,i) for(int i = x;i > y; i--)
#define f(x,y,i) for(int i = x;i < y; i++)
#define ff(x,y,i) for(int i = x;i <= y; i++)
#define FF(x,y,i) for(int i = x;i >= y; i--)
const int N=100500;
const int inf = INT_MAX;
int Max(int a,int b)
{
return a>b?a:b;
}
int Min(int a,int b)
{
return a<b?a:b;
}
int s[405][405];
int dp[405][405];
int main()
{
int n, m, tot, x;
while(~scanf("%d",&n))
{
met(dp,0);
met(s,0);
int maxn = 0;
for(int i = 1;i <= n; i++)
for(int j = 1;j <= i; j++)scanf("%d",&s[i][j]);
for(int i = 1;i <= n; i++)
for(int j = 1;j <= i; j++)
{
dp[i][j] = Max(dp[i][j],dp[i-1][j]+s[i][j]);
dp[i][j] = Max(dp[i][j],dp[i-1][j-1]+s[i][j]);
}
f(1,n+1,i) maxn = Max(maxn,dp[n][i]);
pr(maxn);
}
return 0;
}