알고리즘 공부

백준 숫자판 점프

컴퓨터과학 2023. 8. 4. 19:29

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

 

2210번: 숫자판 점프

111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111, 121112, 121211, 121212, 211111, 211121, 212111, 212121 이 가능한 경우들이다.

www.acmicpc.net

간단한 dfs 문제

#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, k, cnt, power;
	vector<int>save;
	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<int>>>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<vector<bool>>>maps, int h, int n, int m) {
	
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < m; k++) {
				if (maps[i][j][k]==false) {
					return false;
				}
			}
		}
	}
	return true;

}
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 level;
	string nickname;
	
};
struct Room {
	int cnt;
	int roomLevel;
	string status;
	vector<Data>players;
};
bool cmp(const Data &a,const Data &b) {
	return a.nickname < b.nickname;
}
int diri[] = { 1,-1,0,0 };
int dirj[] = { 0,0,1,-1 };
vector<vector<int>>maps;
vector<int>gCnt;
map<string, bool>anw;
void dfs(Point k) {
	if (k.cnt == 6) {
		string str="";
		for (int i = 0; i < k.save.size(); i++) {
			char c= k.save[i] + '0';
		
			 str.push_back(c);
		}
		anw[str] = true;
		
		return;
	}

	for (int i = 0; i < 4; i++) {
		Point tmpp;
		tmpp.i = k.i + diri[i];
		tmpp.j = k.j + dirj[i];
		if (tmpp.i == -1 || tmpp.j == -1 || tmpp.i >= 5 || tmpp.j >= 5) {
			continue;
		}
		tmpp.cnt = k.cnt + 1;
		tmpp.save = k.save;
		tmpp.save.push_back(maps[tmpp.i][tmpp.j]);
		dfs(tmpp);
	}

}
int main() {
	
	for (int i = 0; i < 5; i++) {
		vector<int>tmpMaps;
		for (int j = 0; j < 5; j++) {
			int tmp;
			cin >> tmp;
			tmpMaps.push_back(tmp);
		}
		maps.push_back(tmpMaps);
	}
	
	
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			Point start;
			start.i = i;
			start.j = j;
			start.cnt = 1;
			start.save.push_back(maps[i][j]);
			dfs(start);
		}
	}
	cout << anw.size();
	return 0;
}