๐ป
[๋ฐฑ์ค] ๋ฐฑํธ๋ํน - 2210. ์ซ์ํ ์ ํ ๋ณธ๋ฌธ
[๋ฐฑ์ค] ๋ฐฑํธ๋ํน - 2210. ์ซ์ํ ์ ํ
๋ํจ๋ 2020. 3. 8. 21:55๋ฌธ์
5×5 ํฌ๊ธฐ์ ์ซ์ํ์ด ์๋ค. ๊ฐ๊ฐ์ ์นธ์๋ ์ซ์(digit, 0๋ถํฐ 9๊น์ง)๊ฐ ์ ํ ์๋ค. ์ด ์ซ์ํ์ ์์์ ์์น์์ ์์ํด์, ์ธ์ ํด ์๋ ๋ค ๋ฐฉํฅ์ผ๋ก ๋ค์ฏ ๋ฒ ์ด๋ํ๋ฉด์, ๊ฐ ์นธ์ ์ ํ์๋ ์ซ์๋ฅผ ์ฐจ๋ก๋ก ๋ถ์ด๋ฉด 6์๋ฆฌ์ ์๊ฐ ๋๋ค. ์ด๋์ ํ ๋์๋ ํ ๋ฒ ๊ฑฐ์ณค๋ ์นธ์ ๋ค์ ๊ฑฐ์ณ๋ ๋๋ฉฐ, 0์ผ๋ก ์์ํ๋ 000123๊ณผ ๊ฐ์ ์๋ก ๋ง๋ค ์ ์๋ค.
์ซ์ํ์ด ์ฃผ์ด์ก์ ๋, ๋ง๋ค ์ ์๋ ์๋ก ๋ค๋ฅธ ์ฌ์ฏ ์๋ฆฌ์ ์๋ค์ ๊ฐ์๋ฅผ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
์ ๋ ฅ
๋ค์ฏ ๊ฐ์ ์ค์ ๋ค์ฏ ๊ฐ์ ์ ์๋ก ์ซ์ํ์ด ์ฃผ์ด์ง๋ค.
์ถ๋ ฅ
์ฒซ์งธ ์ค์ ๋ง๋ค ์ ์๋ ์๋ค์ ๊ฐ์๋ฅผ ์ถ๋ ฅํ๋ค.
์์ ์ ๋ ฅ1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 2 1
1 1 1 1 1
์์ ์ถ๋ ฅ1
15
ํํธ
111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111, 121112, 121211, 121212, 211111, 211121, 212111, 212121 ์ด ๊ฐ๋ฅํ ๊ฒฝ์ฐ๋ค์ด๋ค.
์๊ฐ
์ซ์ ์ค๋ณต์ฒดํฌ๋ฅผ ์ด๋ป๊ฒ ํด์ผ ํ๋ ๊ณ ๋ฏผํ์๋ค. ์ฒ์์์ฑํ๋ ์ฝ๋๋ ์๊ฐ์ด๊ณผ๊ฐ ๋ฌ๋ค. ์คํ๋๋ฌธ์ ๊ทธ๋ฐ ๊ฒ ๊ฐ๊ธฐ๋ ํ๊ณ ๋ฐฐ์ด์ 6์๋ฆฌ์ซ์ ๊ฐ ๋ฃ๊ณ ์ค๋ณต์ฒดํฌ true, false ํ๋ คํ์๋ค.
๊ฒ์ํด๋ณด๋ set์ด๋ผ๋ ์๋ฃํ์ด ์๋๋ผ. ์ค๋ณต์ ์ ๊ฑฐํ์ง ์๋ ๊ฒ ํน์ง์ด๊ณ , ์ค๋ณต์ ํ์ฉํ๋ ค๋ฉด multiset์ ์ฌ์ฉํด์ผํ๋ค.
์ ๋ต๋ฅ ์ฒ๋ผ ์ฌ์ด ๋ฌธ์ ๋ ์๋์๋ ๊ฑฐ ๊ฐ์๋ฐ ํ ...
http://www.cplusplus.com/reference/set/set/
set - C++ Reference
difference_typea signed integral type, identical to: iterator_traits ::difference_type usually the same as ptrdiff_t
www.cplusplus.com
์์ฑํ ์ฝ๋
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include <iostream>
#include <set>
using namespace std;
int digit[5][5];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int num;
set<int> s;
void DFS(int x, int y, int n){
int temp = 0;
if(n == 6){
s.insert(num);
return;
}
for(int i=0; i<4; i++){
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || ny < 0 || nx >= 5 || ny >= 5)
continue;
temp = num;
num = (num * 10) + digit[nx][ny];
DFS(nx, ny, n+1);
num = temp;
}
}
int main(int argc, const char * argv[]) {
// insert code here...
for(int i=0; i<5; i++){
for(int j=0; j<5; j++){
cin >> digit[i][j];
}
}
for(int i=0; i<5; i++){
for(int j=0; j<5; j++){
DFS(i, j, 0);
}
}
cout << s.size();
return 0;
}
Colored by Color Scripter
|
'์๊ณ ๋ฆฌ์ฆ > ๋ฌธ์ ํ์ด Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] ๊ทธ๋ฆฌ๋์๊ณ ๋ฆฌ์ฆ - 2217.๋กํ (0) | 2020.03.14 |
---|---|
[๋ฐฑ์ค] ์๋ฎฌ๋ ์ด์ - 2164. ์นด๋2 (0) | 2020.03.13 |
[๋ฐฑ์ค] DFS์BFS - 2583. ์์ญ ๊ตฌํ๊ธฐ(BFSํ์ด) (0) | 2020.03.08 |
[๋ฐฑ์ค] ๋ฌธ์์ด์ฒ๋ฆฌ - 10808. ์ํ๋ฒณ ๊ฐ์ (0) | 2020.03.08 |
[๋ฐฑ์ค] ๋ฌธ์์ด์ฒ๋ฆฌ - 9935. ๋ฌธ์์ด ํญ๋ฐ (0) | 2020.03.05 |