#include<iostream>
using namespace std;
class test{
public:
int a[101][101], n;
int cache[101][101];
void input();
int calc(int ,int);
test(){
for(int i=0;i<101;i++)
fill_n(cache[i], 101, -1);
}
};
void test::input()
{
cin>>n;
for(int i=0;i<n;i++)
for(int j=0;j<=i;j++)
cin>>a[i][j];
}
int test::calc (int i , int j)
{
int t1,t2,t;
if(i>n)
return 0;
if(cache[i][j]== -1)
{
t1 = calc(i+1 ,j);
t2 = calc(i+1,j+1);
t= max(t1,t2) + a[i][j] ;
cache[i][j]= t;
}
else
{
t=cache[i][j];
}
return t;
}
int main(){
std::ios_base::sync_with_stdio(false);
int t,i=0;
cin>>t;
int p=t;
test s[t];
while(t)
{
s[i].input();
i++;
t--;
}
for(int i=0;i<p;i++)
{
cout<<s[i].calc(0 , 0)<<endl;
}
return 0;
}
Any hopes?