求助,样例对的,但是全红
查看原帖
求助,样例对的,但是全红
1536506
cezq3013463951楼主2024/10/24 19:47
#include<iostream>
#include<cmath>
using namespace std;
int map[9][9];
int walk(int map[9][9],int N,int x1,int y1,int x2,int y2,int sum) {
	int M = 0;
	if (x1 == x2 && y1 == y2)sum += map[x1][y1];
	else sum += map[x1][y1]+ map[x2][y2];
	if (x1 == N && y1 == N && x2 == N && y2 == N)return sum;
	if (x1 < N && x2 < N)M=max(M, walk(map, N, x1 + 1, y1, x2 + 1, y2, sum));
	if (x1 < N && y2 < N)M = max(M, walk(map, N, x1 + 1, y1, x2, y2 + 1, sum));
	if (y1 < N && x2 < N)M = max(M, walk(map, N, x1, y1 + 1, x2 + 1, y2, sum));
	if (y1 < N && y2 < N)M = max(M, walk(map, N, x1, y1 + 1, x2, y2 + 1, sum));
	return M;
}
int main() {
	int N;
	int M = 0;
	cin >> N;
	while (1) {
		int x, y, socer;
		cin >> x >> y >> socer;
		if (x == 0 && y == 0 && socer == 0)break;
		else map[x][y] = socer;
	}
	M = walk(map, N-1, 0, 0, 0, 0, 0);
	cout << M << endl;
}
2024/10/24 19:47
加载中...