fork download
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int dp[210][210];
vector<int>arr[210];
int n,test,i,j,k,add,temp;
int rec(int row,int column)
{
    if(dp[row][column]!=-1)
    {
        return dp[row][column];
    }
    if(row<0||column>=arr[row].size())
    {
        return 0;
    }
    else if(row<n)
    {
        dp[row][column]=arr[row][column]+max(rec(row-1,column),rec(row-1,column-1));
        cout<<"dp "<<dp[row][column]<<" "<<row<<" "<<column<<endl;
        return dp[row][column];
    }
    else
    {
        dp[row][column]=arr[row][column]+max(rec(row-1,column+1),rec(row-1,column));
        cout<<"dp big "<<dp[row][column]<<" "<<row<<" "<<column<<endl;
        return dp[row][column];
    }
}

int main()
{
    //freopen("tempin.txt","r",stdin);
    //freopen("tempout.txt","w",stdout);
    cin>>test;
    for(i=0;i<test;i++)
    {
        cin>>n;
        memset(dp,-1,sizeof dp);
        for(j=0;j<(2*n)-1;j++)
        {
            arr[j].clear();
        }
        for(j=0,add=1;j<n;j++,add++)
        {
            for(k=0;k<add;k++)
            {
                cin>>temp;
                arr[j].push_back(temp);
                //cout<<"j "<<j<<" k "<<k<<endl;
            }
        }
        for(j=n,add=n-1;j<(2*n);j++,add--)
        {
            for(k=0;k<add;k++)
            {
                cin>>temp;
                arr[j].push_back(temp);
                //cout<<"j "<<j<<" k "<<k<<endl;
            }
        }
        cout<<"Case "<<i+1<<": "<<rec((2*n)-2,0)<<endl;
    }
    return 0;
}
Success #stdin #stdout 0s 3640KB
stdin
2
4
7
6 4
2 5 10
9 8 12 2
2 12 7
8 2
10
2
1
2 3
1
stdout
Case 1: dp 7 0 0
dp 11 1 1
dp 21 2 2
dp 23 3 3
dp 13 1 0
dp 18 2 1
dp 33 3 2
dp big 40 4 2
dp 15 2 0
dp 26 3 1
dp big 45 4 1
dp big 47 5 1
dp 24 3 0
dp big 28 4 0
dp big 53 5 0
dp big 63 6 0
63
Case 2: dp 1 0 0
dp 4 1 1
dp 3 1 0
dp big 5 2 0
5