문제
2주차 [백준] 바닥장식
접근
풀이
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector<vector<bool>> visited;
vector<vector<int>> room;
int d, w;
int sum = 0;
void CheckTile(int curTile, int nd, int nw) {
if (nd >= d || nw >= w) { sum++; return; }
if (curTile != room[nd][nw]) { sum++; return; }
if (curTile == 0) { CheckTile(room[nd][nw], nd , nw + 1); }
if (curTile == 1) { CheckTile(room[nd][nw], nd + 1, nw ); }
visited[nd][nw] = true;
}
void solution(int d, int w, vector<vector<int>> room) {
for (int i = 0; i < d; i++)
{
for (int j = 0; j < w; j++)
{
if (visited[i][j] == true) continue;
CheckTile(room[i][j], i, j);
}
}
}
int main() {
cin >> d >> w;
room.resize(d); visited.resize(d);
for (int i = 0; i < d; i++) {
for (int j = 0; j < w; j++) {
char temp; cin >> temp;
if (temp == '-') room[i].push_back(0);
else room[i].push_back(1);
visited[i].push_back(false);
}
}
solution(d, w, room);
cout << sum;
return 0;
}
}