// Problem: P1004 [NOIP2000 提高组] 方格取数
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1004
// Memory Limit: 125 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(1,2,3,"Ofast","inline")
#define lowbit(x) ((x)&(-(x)))
typedef long long LL;
typedef unsigned long long ULL;
const int N=10;
const int INF=2e9+10;
inline int read(){
int ret=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-') f=-f; ch=getchar(); }
while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
return ret*f;
}
inline void write(int x){
if(x<0){ putchar('-'); x=-x; }
if(x>9) write(x/10);
putchar(x%10+'0');
}
int a[N][N];
int f[N<<1][N][N][N][N];
int main(){
int x,y,x0,y0,s,v,n;
n=read();
while(~scanf("%d",&x)&&x!=0){
scanf("%d%d",&y,&v);
a[x][y]=v;
}
for(s=1;s<=n*2-1;++s){
for(x=1;x<=n;++x){
y=s+1-x;
for(x0=1;x0<=n;++x0){
y0=s+1-x0;
f[s][x][y][x0][y0]=max(max(f[s-1][x-1][y][x0-1][y0],
f[s-1][x][y-1][x0][y0-1]),
max(f[s-1][x-1][y][x0][y0-1],
f[s-1][x][y-1][x0-1][y0])
)+(x==x0&&y==y0?a[x][y]:a[x][y]+a[x0][y0]);
//printf("s=%d,%d\n",s,f[s][x][y][x0][y0]);
}
}
}
write(f[n*2-1][n][n][n][n]);
return 0;
}
RT,三层循环为什么不对呢?
