'commit'
This commit is contained in:
56
TangDou/LanQiaoBei/LanQiao14STEMA202303/5.cpp
Normal file
56
TangDou/LanQiaoBei/LanQiao14STEMA202303/5.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
int dx[] = {-1, 0, 1, 0};
|
||||
int dy[] = {0, 1, 0, -1};
|
||||
|
||||
struct Node {
|
||||
int x, y;
|
||||
} b[N];
|
||||
int bl;
|
||||
|
||||
char a[N][N];
|
||||
int n, m;
|
||||
int res;
|
||||
|
||||
void dfs(int u, int sum) {
|
||||
if (u == bl + 1) {
|
||||
res = max(res, sum);
|
||||
return;
|
||||
}
|
||||
dfs(u + 1, sum);
|
||||
|
||||
Node c[N];
|
||||
int cl = 0;
|
||||
|
||||
int cx = b[u].x, cy = b[u].y;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int tx = dx[i] + cx, ty = dy[i] + cy;
|
||||
if (tx <= 0 || tx > n || ty <= 0 || ty > m) continue;
|
||||
if (a[tx][ty] == 'C' || a[tx][ty] == 'D' || a[tx][ty] == 'Z') return;
|
||||
c[++cl] = {tx, ty};
|
||||
}
|
||||
|
||||
a[cx][cy] = 'Z';
|
||||
for (int i = 1; i <= cl; i++) a[c[i].x][c[i].y] += 2;
|
||||
|
||||
dfs(u + 1, sum + cl + 1);
|
||||
|
||||
a[cx][cy] = 'B';
|
||||
for (int i = 1; i <= cl; i++) a[c[i].x][c[i].y] -= 2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++) {
|
||||
cin >> a[i][j];
|
||||
if (a[i][j] == 'B') b[++bl] = {i, j};
|
||||
}
|
||||
|
||||
dfs(1, 0);
|
||||
|
||||
cout << res << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user