forked from b-chae/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5568.cpp
More file actions
62 lines (54 loc) · 881 Bytes
/
Copy path5568.cpp
File metadata and controls
62 lines (54 loc) · 881 Bytes
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
#include <iostream>
using namespace std;
bool visited[100000000];
int selec[4] = {0, 0, 0, 0};
int ans = 0;
int N, K;
int num[10];
void combine(int n, int* arr) {
if (n == K) {
int a = 0;
for (int i = 0; i < K; i++) {
if (arr[i] < 10) {
a = a * 10 + arr[i];
}
else {
a = a * 100 + arr[i];
}
}
if (!visited[a]) {
ans++;
visited[a] = true;
}
return;
}
for (int i = 0; i < K; i++) {
if (arr[i] == -1) {
arr[i] = selec[n];
combine(n + 1, arr);
arr[i] = -1;
}
}
}
void solve(int s, int selected) {
if (s == N+1) return;
if (selected == K) {
int arr[4] = { -1,-1,-1,-1 };
combine(0, arr);
return;
}
selec[selected] = num[s];
solve(s + 1, selected + 1);
solve(s + 1, selected);
}
int main()
{
int i;
cin >> N >> K;
for (i = 0; i < N; i++) {
cin >> num[i];
}
solve(0, 0);
cout << ans << "\n";
return 0;
}