状态方程f[j]=max(f[j]+tri[i][j],f[j+1]+tri[i][j])。
//
// main.cpp
// Richard
//
// Created by 邵金杰 on 16/9/9.
// Copyright © 2016年 邵金杰. All rights reserved.
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100+10;
int tri[maxn][maxn],f[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(f,0,sizeof(f));
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
scanf("%d",&tri[i][j]);
if(i==n) f[j]=tri[i][j];
}
}
for(int i=n-1;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
f[j]=max(f[j]+tri[i][j],f[j+1]+tri[i][j]);
}
}
cout<<f[1]<<endl;
}
return 0;
}