-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2819.cpp
68 lines (65 loc) · 1.15 KB
/
2819.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// 2819. 격자판의 숫자 이어 붙이기
// 2019.07.16
#include<iostream>
#include<string>
#include<set>
using namespace std;
set<string> s;
int dx[4] = { 0, 0, 1, -1 };
int dy[4] = { 1, -1, 0, 0 };
int map[4][4];
// 모든 경우를 조사하는 함수
void go(int x, int y, string ans, int cnt)
{
if (cnt == 6)
{
s.insert(ans);
return;
}
for (int i = 0; i < 4; i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if (xx >= 4 || yy >= 4 || xx < 0 || yy < 0)
{
continue;
}
else
{
string tmp2 = ans;
char tmp = map[xx][yy]+'0';
ans += tmp;
go(xx, yy, ans, cnt + 1);
ans = tmp2;
}
}
}
int main()
{
int t;
cin >> t;
for (int test_case = 1; test_case <= t; test_case++)
{
s.clear();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
cin >> map[i][j];
}
}
// 모든 경우의 수를 만들어서 set에 저장한다.
// set의 크기가 서로다른 숫자의 개수가 된다.
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
string ans = "";
ans+=(map[i][j] + '0');
go(i, j, ans, 0);
}
}
cout << "#" << test_case << " " << s.size() << endl;
}
return 0;
}