/* ID:chenjiong PROG:numtri LANG:C++ */ #include <stdio.h> #include <string.h> const int MAXN = 1005; int N; int mat[MAXN][MAXN]; int cnt; int sum; int max = 0; void dfs(int x,int y) { if ( x == N ) { if ( sum > max ) max = sum; return; } sum += mat[x + 1][y]; dfs(x + 1,y); sum -= mat[x + 1][y]; sum += mat[x + 1][y + 1]; dfs(x + 1,y + 1); sum -= mat[x + 1][y + 1]; } 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]); sum = mat[0][0]; dfs(0,0); printf("%d\n",max); return 0; }