From 13e41b512c1f2011067d0cd4f7354cdb1853aba9 Mon Sep 17 00:00:00 2001 From: gyunho Date: Wed, 15 Jan 2025 10:11:14 +0900 Subject: [PATCH] 2025-01-15 --- .gitignore | 3 ++- g0rnn/README.md | 34 ++++++++++++++++++++---------- g0rnn/backtracking/15-g0rnn.cpp | 37 +++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 g0rnn/backtracking/15-g0rnn.cpp diff --git a/.gitignore b/.gitignore index b9f4630..6eb604d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .idea/ /.vscode cmake-build-debug/ -CMakeLists.txt \ No newline at end of file +CMakeLists.txt +.clang-tidy \ No newline at end of file diff --git a/g0rnn/README.md b/g0rnn/README.md index f8dcc1e..5907b65 100644 --- a/g0rnn/README.md +++ b/g0rnn/README.md @@ -1,15 +1,27 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :---: | :--------: | :--------: | :---------------------------------------------------------------------------: | :-------------------------------------------------: | -| 1차시 | 2024.10.01 | 구현 | [추억 점수](https://school.programmers.co.kr/learn/courses/30/lessons/176963) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/35 | -| 2차시 | 2024.10.03 | 트리 | [LCA2](https://school.programmers.co.kr/learn/courses/30/lessons/176963) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/7 | -| 3차시 | 2024.10.04 | 문자열 | [잃어버린 괄호](https://www.acmicpc.net/problem/1541) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/9 | -| 4차시 | 2024.10.11 | 브루트포스 | [영화감독 숌](https://www.acmicpc.net/problem/1436) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/15 | -| 5차시 | 2024.11.01 | BFS/DFS | [연구소](https://www.acmicpc.net/problem/14502) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/17 | -| 6차시 | 2024.11.06 | 구현 | [통계학](https://www.acmicpc.net/problem/2108) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/23 | -| 7차시 | 2024.11.25 | 구현 | [팰린드롬 만들기](https://www.acmicpc.net/problem/1213) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/31 | -| 8차시 | 2024.11.29 | 문자열 | [잠수함식별](https://www.acmicpc.net/problem/2671) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/35 | -| 9차시 | 2024.12.04 | 그리디 | [A->B](https://www.acmicpc.net/problem/16953) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/39 | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +|:----:|:----------:|:-------:|:-------------------------------------------------------------------------:|:---------------------------------------------------:| +| 1차시 | 2024.10.01 | 구현 | [추억 점수](https://school.programmers.co.kr/learn/courses/30/lessons/176963) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/35 | +| 2차시 | 2024.10.03 | 트리 | [LCA2](https://school.programmers.co.kr/learn/courses/30/lessons/176963) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/7 | +| 3차시 | 2024.10.04 | 문자열 | [잃어버린 괄호](https://www.acmicpc.net/problem/1541) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/9 | +| 4차시 | 2024.10.11 | 브루트포스 | [영화감독 숌](https://www.acmicpc.net/problem/1436) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/15 | +| 5차시 | 2024.11.01 | BFS/DFS | [연구소](https://www.acmicpc.net/problem/14502) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/17 | +| 6차시 | 2024.11.06 | 구현 | [통계학](https://www.acmicpc.net/problem/2108) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/23 | +| 7차시 | 2024.11.25 | 구현 | [팰린드롬 만들기](https://www.acmicpc.net/problem/1213) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/31 | +| 8차시 | 2024.11.29 | 문자열 | [잠수함식별](https://www.acmicpc.net/problem/2671) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/35 | +| 9차시 | 2024.12.04 | 그리디 | [A->B](https://www.acmicpc.net/problem/16953) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/39 | +| 10차시 | 2024.12.20 | 그래프 | [결혼식](https://www.acmicpc.net/problem/5567) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/40 | +| 11차시 | 2024.12.30 | dp | [기타리스트](https://www.acmicpc.net/problem/1495) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/49 | +| 12차시 | 2025.01.02 | bfs | [회장뽑기](https://www.acmicpc.net/problem/2660) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/50 | +| 13차시 | 2025.01.05 | 백트래킹 | [스타트와 링크](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/52 | +| 14차시 | 2025.01.07 | 백트레킹 | [N-Queen](https://www.acmicpc.net/problem/9663) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/53 | +| 15차시 | 2025.01.15 | 백트래킹 | [알파벳](https://www.acmicpc.net/problem/1987) | https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/60 | + + + + + + --- diff --git a/g0rnn/backtracking/15-g0rnn.cpp b/g0rnn/backtracking/15-g0rnn.cpp new file mode 100644 index 0000000..a27dc41 --- /dev/null +++ b/g0rnn/backtracking/15-g0rnn.cpp @@ -0,0 +1,37 @@ +// +// Created by 김균호 on 2025. 1. 14.. +// +#include +using namespace std; + +int r, c; +string line; +int answer = 0; +char board[20][20]; +bool visited[26]; +int offset[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; + +void backtrack(int x, int y, int cnt) { + answer = max(answer, cnt); + for (auto &dir: offset) { + int nx = x + dir[0]; + int ny = y + dir[1]; + if (0 <= nx && nx < c && 0 <= ny && ny < r && !visited[board[ny][nx] - 'A']) { + visited[board[ny][nx] - 'A'] = true; + backtrack(nx, ny, cnt + 1); + visited[board[ny][nx] - 'A'] = false; + } + } +} + +int main() { + cin >> r >> c; + for (int i = 0; i < r; i++) { + cin >> line; + for (int k = 0; k < line.size(); k++) board[i][k] = line[k]; + } + visited[board[0][0] - 'A'] = true; + backtrack(0, 0, 1); + cout << answer; + return 0; +}