[ AGC004 E ] Salvage Robots

题目

Atcoder

思路

1.jpg
2.jpg

代码

#include <iostream>
#include <algorithm>
using namespace std;
int n , m , x , y , v[105][105][2];
short f[105][105][105][105];
signed main() {
	cin >> n >> m;
	char c;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m && cin >> c; ++j)
			if (c == 'E') x = i , y = j;
			else if(c == 'o') {
				v[i][j][0] = v[i - 1][j][0] + 1;
				v[i][j][1] = v[i][j - 1][1] + 1;
			} else {
				v[i][j][0] = v[i - 1][j][0];
				v[i][j][1] = v[i][j - 1][1];
			}
	int res = 0;
	for (int l = 0; l <= y - 1; ++l)
		for (int r = 0; r <= m - y; ++r)
			for (int u = 0; u <= x - 1; ++u) 
				for (int d = 0; d <= n - x; ++d) {
					res = max(res, (int)f[l][r][u][d]);
					short &t = f[l][r][u][d];
					short &tl = f[l + 1][r][u][d];
					short &tr = f[l][r + 1][u][d];
					short &tu = f[l][r][u + 1][d];
					short &td = f[l][r][u][d + 1];
					if(l + r < y - 1) tl = max((int)tl, (int)t + v[min(x + d , n - u)][y - l - 1][0] - v[max(x - u - 1 , d)][y - l - 1][0]);
					if(l + r < m - y) tr = max((int)tr, (int)t + v[min(x + d , n - u)][y + r + 1][0] - v[max(x - u - 1 , d)][y + r + 1][0]);
					if(u + d < x - 1) tu = max((int)tu, (int)t + v[x - u - 1][min(y + r , m - l)][1] - v[x - u - 1][max(y - l - 1 , r)][1]);
					if(u + d < n - x) td = max((int)td, (int)t + v[x + d + 1][min(y + r , m - l)][1] - v[x + d + 1][max(y - l - 1 , r)][1]);
				}
	cout << res << endl;
	return 0;
}
posted @ 2021-05-12 22:30  Protein_lzl  阅读(53)  评论(0编辑  收藏  举报