代码在此
#include <bits/stdc++.h>
using namespace std;
int f[55][55][55][55],n,m,sweet[55][55];
int main(){
cin>>n;
int a,b,c;
cin>>a>>b>>c;
while(a!=0||b!=0||c!=0){
sweet[a][b]=c;
cin>>a>>b>>c;
}
for(int x1=1;x1<=n;x1++){
for(int y1=1;y1<=n;y1++){
for(int x2=1;x2<=n;x2++){
for(int y2=1;y2<=n;y2++){
if(x1==x2||y1==y2){
continue;
}
f[x1][y1][x2][y2]=max(f[x1][y1][x2][y2],f[x1][y1-1][x2-1][y2]);
f[x1][y1][x2][y2]=max(f[x1][y1][x2][y2],f[x1][y1-1][x2][y2-1]);
f[x1][y1][x2][y2]=max(f[x1][y1][x2][y2],f[x1-1][y1][x2-1][y2]);
f[x1][y1][x2][y2]=max(f[x1][y1][x2][y2],f[x1-1][y1][x2][y2-1]);
f[x1][y1][x2][y2]+=sweet[x1][y1]+sweet[x2][y2];
}
}
}
}
cout<<f[n][n-1][n-1][n];
return 0;
}
蒟蒻不知道为什么错了,求各位大佬帮助一下