Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 | 29 |
30 | 31 |
Tags
- Reversing
- ๋์ ํฉ
- error
- c++
- BFS
- java
- OS
- dynamic debugging
- GCP
- ์ฐ์ ์์ ํ
- web
- JPA
- ๋ฐ์ดํฌ์คํธ๋ผ
- ์๋ฎฌ๋ ์ด์
- ์ด๋ถ ํ์
- Spring
- ์ต๋จ ๊ฒฝ๋ก
- ๊ตฌํ
- ๊ทธ๋ฆฌ๋
- ๋ฌธ์์ด
- thymeleaf
- ๋ฐฑํธ๋ํน
- ๋งต
- dfs
- ์ฌ๊ท
- DP
- ์คํ
- ๋ถํ ์ ๋ณต
- ์์ ์ ๋ ฌ
- CVE
Archives
- Today
- Total
hades
[Baekjoon] 1987๋ฒ: ์ํ๋ฒณ ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/1987
๐ ์ค๊ณ
์ด๋ค ์ํ๋ฒณ์ ์ค๋ณตํด์ ๋ฐฉ๋ฌธํ ์ ์์ผ๋ฏ๋ก, ์ํ๋ฒณ์ ๋ํ ๋ฐฉ๋ฌธ ์ฌ๋ถ๋ฅผ visited์ ์ ์ฅํ๋ค.
๋ง์ด ์ต๋ ์ฐ์ํด์ ๋ช ์นธ์ ์ง๋ ์ ์๋์ง ๊ตฌํ๊ธฐ ์ํด์๋ DFS๋ฅผ ์ด์ฉํด์ผ ํ๋ค. ์ง๋๋ ๊ฒฝ๋ก ์ค๊ฐ์ ๋ค๋ฅธ ๋ฐฉํฅ์ผ๋ก ๊ฒฝ๋ก๋ฅผ ํ์ํ๊ธฐ ์ํด ๋ฐฑํธ๋ํน์ ์ด์ฉํ๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int r, c, result = 0;
int dx[] = { -1,1,0,0 };
int dy[] = { 0,0,-1,1 };
vector<vector<char>> board(20, vector<char>(20));
vector<bool> visited(26);
string s;
void dfs(int cur_x, int cur_y, int temp_result) {
result = max(result, temp_result);
for (int i = 0; i < 4; i++) {
int new_x = cur_x + dx[i];
int new_y = cur_y + dy[i];
if (!(new_x >= 0 && new_x < r && new_y >= 0 && new_y < c)) {
continue;
}
int new_alphabet = board[new_x][new_y];
if (!visited[new_alphabet - 'A']) {
visited[new_alphabet - 'A'] = true;
dfs(new_x, new_y, temp_result + 1);
visited[new_alphabet - 'A'] = false;
}
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> r >> c;
for (int i = 0; i < r; i++) {
cin >> s;
for (int j = 0; j < c; j++) {
board[i][j] = s[j];
}
}
visited[board[0][0] - 'A'] = true;
dfs(0, 0, 1);
cout << result << "\n";
return 0;
}
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 9465๋ฒ: ์คํฐ์ปค (0) | 2024.08.11 |
---|---|
[Baekjoon] 2096๋ฒ: ๋ด๋ ค๊ฐ๊ธฐ (0) | 2024.08.10 |
[Baekjoon] 1918๋ฒ: ํ์ ํ๊ธฐ์ (0) | 2024.08.08 |
[Baekjoon] 11501๋ฒ: ์ฃผ์ (0) | 2024.08.07 |
[Baekjoon] 11675๋ฒ: ํ์๋จธ์ (0) | 2024.08.06 |