【未完】一本通 1277:【例9.21】方格取数
方格取数
#include <iostream>
#include <cstdio>
using namespace std;
//Mystery_Sky
//
#define M 11
int f[M][M][M][M], a[M][M];
int n, x, y, z;
int max1, max2;
int main() {
scanf("%d", &n);
while(scanf("%d%d%d", &x, &y, &z) == 3 && x && y && z) {
a[x][y] = z;
}
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++) {
max1 = max(f[i-1][j][k-1][l], f[i][j-1][k][l-1]);
max2 = max(f[i-1][j][k][l-1], f[i][j-1][k-1][l]);
f[i][j][k][l] = max(max1, max2) + a[i][j];
if(i != k && j != l) f[i][j][k][l] += a[k][l];
}
}
}
}
printf("%d\n", f[n][n][n][n]);
return 0;
}
唯愿,青春不辜负梦想,未来星辰闪耀