[λ°±μ€] λ°±νΈλνΉ - 2210. μ«μν μ ν
λ¬Έμ
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
|