일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 조합론
- back propagation
- 미래는_현재와_과거로
- 문자열
- NEXT
- 플로이드 와샬
- pytorch
- 세그먼트 트리
- lazy propagation
- 알고리즘
- object detection
- DP
- Overfitting
- 우선 순위 큐
- 이분 탐색
- 회고록
- 너비 우선 탐색
- 2023
- BFS
- 분할 정복
- 크루스칼
- 가끔은 말로
- dropout
- 자바스크립트
- 가끔은_말로
- c++
- 백트래킹
- tensorflow
- 다익스트라
- dfs
Archives
- Today
- Total
Doby's Lab
백준 2210번: 숫자판 점프 (C++) 본문
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
Solved By: DFS
#include <iostream>
#include <set>
using namespace std;
string board[6][6];
bool visited[6][6];
struct Dir{
int y, x;
};
Dir dir[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int res = 0;
set<string> st;
void dfs(int y, int x, string s){
if(s.length() == 6){
if(!st.count(s)){
//cout << s << '\n';
st.insert(s);
res++;
}
return;
}
for(int i = 0; i < 4; i++){
int dy = y + dir[i].y;
int dx = x + dir[i].x;
if(dy < 1 || dy > 5 || dx < 1 || dx > 5) continue;
dfs(dy, dx, s + board[dy][dx]);
}
}
int main(){
for(int i = 1; i <= 5; i++){
for(int j = 1; j <= 5; j++){
cin >> board[i][j];
}
}
for(int i = 1; i <= 5; i++){
for(int j = 1; j <= 5; j++){
dfs(i, j, board[i][j]);
}
}
cout << res;
return 0;
}
728x90
'PS > BOJ' 카테고리의 다른 글
백준 17362번: 수학은 체육과목 입니다 2 (Python) (0) | 2022.07.26 |
---|---|
백준 13237번: Binary tree (C++) (0) | 2022.07.24 |
백준 17103번: 골드바흐 파티션 (C++) (0) | 2022.07.24 |
백준 24309번: 2021은 무엇이 특별할까? (C++) (0) | 2022.07.21 |
백준 24479번: 알고리즘 수업 - 깊이 우선 탐색 1 (C++) (0) | 2022.07.20 |