求助
  • 板块P2295 MICE
  • 楼主FANTA5TlC
  • 当前回复0
  • 已保存回复0
  • 发布时间2020/6/10 20:45
  • 上次更新2023/11/7 00:53:06
查看原帖
求助
297798
FANTA5TlC楼主2020/6/10 20:45
#include <bits/stdc++.h>
#define pi acos(-1)
using namespace std;
/*
template<typename T> void read(T &x) {
	int f = 1;
	x = 0;
	char c = getchar();
	while (!isdigit(c)) {
		if (c == '-') f = -1;
		c = getchar();
	}
	while (isdigit(c)) {
		x = x * 10 + c - '0';
		c = getchar();
	}
	x = x * f;
}
*/
int a[1005][1005];
bool vm[1005][1005];//看见不同老鼠
bool vi[1005][1005];//走路不重
int mi[1005][1005];
int maxn = -1;
int n, m, cnt;
void dfs(int x, int y){
	if (x > n) return;
	if (y > m) return;
	if (x < 1) return;
	if (y < 1) return;
	if (vi[x][y] == true) return;
	vi[x][y] = true;
	mi[x][y] = cnt;
	if (vm[x + 1][y] == false){
		cnt += a[x + 1][y];
		vm[x + 1][y] = true;
	}
	if (vm[x][y + 1] == false){
		cnt += a[x][y + 1];
		vm[x][y + 1] = true;
	}
	dfs(x + 1, y);
	dfs(x, y + 1);
 	cnt -= a[x + 1][y];
	cnt -= a[x][y + 1];
	vm[x][y + 1] = false;
	vm[x + 1][y] = false;
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1;  i <= n; ++i){
		for (int j = 1; j <= m; ++j){
			cin >> a[i][j];
		}
	}
	cnt = 0;
	dfs(1, 1);
//	for (int i = 1;  i <= n; ++i){
//		for (int j = 1; j <= m; ++j){
//			cout << mi[i][j] << "   ";
//		}
//		cout << endl;
//	}
	cout << mi[n][m] << endl;
}

2020/6/10 20:45
加载中...