https://www.acmicpc.net/problem/1189

 

1189번: 컴백홈

첫 줄에 정수 R(1 ≤ R ≤ 5), C(1 ≤ C ≤ 5), K(1 ≤ K ≤ R×C)가 공백으로 구분되어 주어진다. 두 번째부터 R+1번째 줄까지는 R×C 맵의 정보를 나타내는 '.'과 'T'로 구성된 길이가 C인 문자열이 주어진다

www.acmicpc.net

쉽네요

#include <iostream>
#include <vector>
#include <queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<map>
#include<stack>
using namespace std;

struct Point {
	int i, j, t, cnt, power;
	char c;
};

void Prints(vector<vector<int>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
}

void Prints(vector<vector<bool>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
}
void Prints(vector<vector<char>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j];
		}
		cout << endl;
	}
	cout << endl;
}
void Prints(vector<vector<vector<char>>>maps, int n, int m, int k) {
	for (int t = 0; t < k; t++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << maps[t][i][j];
			}
			cout << endl;
		}
		cout << endl;
	}
	cout << endl;
}

void Prints(vector<vector<vector<bool>>>maps, int n, int m, int k) {
	for (int t = 0; t < k; t++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << maps[t][i][j];
			}
			cout << endl;
		}
		cout << endl;
	}
	cout << endl;
}
void Prints(vector<int>line, int n) {
	for (int i = 0; i < n; i++) {
		cout << line[i] << ",";
	}
	cout << endl;
}
void Prints(string str, int n) {
	for (int i = 0; i < n; i++) {
		cout << str[i] << ",";
	}
	cout << endl;
}

bool checkmaps(vector<vector<int>>maps, vector<vector<int>>anw, int n, int m) {
	bool bCheck = false;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (maps[i][j] != anw[i][j]) {
				bCheck = true;
				i = n + 1;
				j = m + 1;
				continue;
			}
		}

	}
	return bCheck;

}
bool findstart(vector<vector<int>>maps, vector<vector<int>>anw, int n, int m, int) {
	bool bCheck = false;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (maps[i][j] != anw[i][j]) {
				bCheck = true;
				i = n + 1;
				j = m + 1;
				continue;
			}
		}

	}
	return bCheck;

}

struct Data {
	int index;
	string times;
	
};

vector<vector<bool>>gbVisited;
vector<vector<char>>gmaps;
int r, c, k;
int diri[] = { 1,-1,0,0 };
int dirj[] = { 0,0,1,-1 };
int gCnt = 0;
void dfs(Point start,Point end) {

	gbVisited[start.i][start.j] = true;

	if (start.i == end.i && start.j == end.j) {
		//cout << "finish:"<<start.cnt << endl;
		if (start.cnt == k) {
			gCnt++;
		}
		return;
	}
	for (int i = 0; i < 4; i++) {
		int tmpDiri = start.i + diri[i];
		int tmpDirj = start.j + dirj[i];
		if (tmpDiri==-1|| tmpDirj==-1|| tmpDiri>=r|| tmpDirj>=c) {
			continue;
		}
		if (gbVisited[tmpDiri][tmpDirj]==false) {
			Point tmp;
			tmp.i = tmpDiri;
			tmp.j = tmpDirj;
			tmp.cnt = start.cnt + 1;
			//cout << tmp.i << "," << tmp.j << endl;
			dfs(tmp,end);
			gbVisited[tmpDiri][tmpDirj] = false;
		}
	}
}
int main() {
	
	cin >> r >> c >> k;
	vector<vector<char>>maps;
	vector<bool>tmpVisited(c, false);
	vector<vector<bool>>bVisited(r,tmpVisited);

	for (int i = 0; i < r; i++) {
		vector<char>tmpMaps;
		for (int j = 0; j < c; j++) {
			char tmp;
			cin >> tmp;
			if (tmp == 'T') {
				bVisited[i][j] = true;
			}
			tmpMaps.push_back(tmp);
		}
		maps.push_back(tmpMaps);
	}
	gmaps = maps;
	gbVisited = bVisited;
	Point start;
	Point end;
	start.i = r-1;
	start.j = 0;
	start.cnt = 1;
	end.i = 0;
	end.j = c-1;
	
	dfs(start, end);

	cout << gCnt;
	
	return 0;
}

'알고리즘 공부' 카테고리의 다른 글

백준 한줄로 서기  (0) 2023.08.05
백준 토마토  (1) 2023.08.04
백준 숫자판 점프  (0) 2023.08.04
백준 볼 모으기  (0) 2023.08.04
백준 랭킹전 대기열  (0) 2023.08.04

+ Recent posts