-
[2210] 숫자판 점프BOJ 2022. 2. 5. 08:43
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
<문제>
완전탐색하면 된다. 6개의 숫자가 만들어지면 set에 넣어두면, set의 size가 답이된다.
<소스코드>
#include <bits/stdc++.h>using namespace std;int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};char a[5][5];set<int> st;void f(int cy, int cx, string s) {if (s.length() == 6) {st.insert(stoi(s));return;}int i;for (i = 0; i < 4; i++) {int y = cy + dy[i];int x = cx + dx[i];if (y < 0 || x < 0 || y >= 5 || x >= 5) continue;f(y, x, s + a[y][x]);}}int main(void) {ios_base::sync_with_stdio(0);cin.tie(0);int i, j;for (i = 0; i < 5; i++)for (j = 0; j < 5; j++) cin >> a[i][j];for (i = 0; i < 5; i++)for (j = 0; j < 5; j++) f(i, j, "");cout << st.size();return 0;}'BOJ' 카테고리의 다른 글
[11403] 경로 찾기 (0) 2022.02.05 [11265] 끝나지 않는 파티 (0) 2022.02.05 [2776] 암기왕 (0) 2022.02.04 [11779] 최소비용 구하기 2 (0) 2022.02.03 [18870] 좌표 압축 (0) 2022.02.03