暴力:\(O(n^4)\)
const int N=10;
int f[N][N][N][N];
int g[N][N];
int n;
int main()
{
cin>>n;
while(1)
{
int a,b,c;
cin>>a>>b>>c;
if(!a && !b && !c) break;
g[a][b]=c;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
for(int l=1;l<=n;l++)
{
f[i][j][k][l]=max(max(f[i-1][j][k-1][l],f[i][j-1][k-1][l]),
max(f[i-1][j][k][l-1],f[i][j-1][k][l-1]))+g[i][j]+g[k][l];
if(i == k && j == l) f[i][j][k][l]-=g[i][j];
}
cout<<f[n][n][n][n]<<endl;
//system("pause");
}