显示代码纯文本
#include<cstdio>
#include<iostream>
using namespace std;
int map[15][15],f[15][15][15][15];
int main(){
freopen("fgqs.in","r",stdin);
freopen("fgqs.out","w",stdout);
int n;
cin>>n;
int a,b,c;
while(1){
cin>>a>>b>>c;
if(a==0&&b==0&&c==0) break;
map[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][j-1][k][l-1],f[i][j-1][k-1][l]),
max(f[i-1][j][k-1][l],f[i-1][j][k][l-1]));
f[i][j][k][l]+=map[i][j];
if(i!=k||j!=l) f[i][j][k][l]+=map[k][l];
}
cout<<f[n][n][n][n];
return 0;
}