#include <iostream>
#include <stdlib.h>
using namespace std;
#define MAX 100
int d[MAX][MAX];
int num;
int maxSum(int i, int j){
if(i == num)
return d[i][j];
int x = maxSum(i+1, j);
int y = maxSum(i+1, j+1);
return max(x,y) + d[i][j];
}
int main()
{
int i,j;
cin >> num;
for(i = 1; i <= num; i ++)
for(j = 1; j <= i; j ++)
cin >> d[i][j];
cout << maxSum(1,1) << endl;
return 0;
}
#include <iostream>
#include <stdlib.h>
#include <string.h>
#define MAX 100
using namespace std;
int d[MAX][MAX];
int D[MAX][MAX];
int num;
int maxSum(int i, int j){
if (D[i][j]!=-1)
return D[i][j];
if(i == num)
D[i][j]=d[i][j];
else
{
int x = maxSum(i+1, j);
int y = maxSum(i+1, j+1);
D[i][j]=max(x,y)+d[i][j];
}
return D[i][j];
}
int main()
{
int i,j;
cin >> num;
for(i = 1; i <= num; i ++)
for(j = 1; j <= i; j ++)
cin >> d[i][j];
memset(D,-1,sizeof(D));
cout << maxSum(1,1) << endl;
return 0;
}
#include <iostream>
#include <stdlib.h>
#include <string.h>
#define MAX 100
using namespace std;
int d[MAX][MAX];
int num;
int maxSum(int num){
int i, j;
for(i = num - 1; i >= 1; i --)
for(j = 1; j <= i; j ++){
d[i][j] = max(d[i+1][j],d[i+1][j+1]) + d[i][j];
}
return d[1][1];
}
int main()
{
int i,j;
cin >> num;
for(i = 1; i <= num; i ++)
for(j = 1; j <= i; j ++)
cin >> d[i][j];
cout << maxSum(num) << endl;
return 0;
}