4
7
11 6 11 6 3 10 6
7 9 6 13 5 15 5
1 10 12 7 13 7 5
13 11 10 8 10 12 13

5
9

#include <iostream> #include <stack> #include <cstring> using namespace std;
int R, C; //行列数 int rooms[60][60]; int color[60][60]; //方块是否染色过的标记 int
maxRoomArea= 0, roomNum = 0; int roomArea; void Dfs(int i, int k) { if (color[i]
[k])//判断是不是终点，如果是的话跳出 return; ++roomArea;//不是终点的话，最大连通数+1 color[i][k] = roomNum;
//=0房子编号 //判断哪个墙不存在 if ((rooms[i][k] & 1) == 0) Dfs(i, k - 1); //向西走 if ((rooms[
i][k] & 2) == 0) Dfs(i - 1, k); //向北 if ((rooms[i][k] & 4) == 0) Dfs(i, k + 1);
//向东 if ((rooms[i][k] & 8) == 0) Dfs(i + 1, k); //向南 } int main() { cin >> R >>
C; for (int i = 1; i <= R; ++i) for (int k = 1; k <= C; ++k) cin >> rooms[i][k];
//输入每个方格的墙面 memset(color, 0, sizeof(color));//所有的设置为0 for (int i = 1; i <= R; ++
i) for (int k = 1; k <= C; ++k) { if (!color[i][k]) { ++roomNum; roomArea = 0;
Dfs(i, k); maxRoomArea =//判断哪一次的房间数多，就把哪个赋给max max(roomArea, maxRoomArea); } }
cout<< roomNum << endl; cout << maxRoomArea << endl; }