-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1062.cpp
64 lines (54 loc) · 1.21 KB
/
1062.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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int N, K;
bool alpha[26];
int ans;
vector<string> v;
void dfs(int idx, int remain){
if(!remain){
int cnt = 0;
for(string elem : v){
bool flag = true;
for(char ch : elem){
if(!alpha[ch - 'a']){
flag = false;
break;
}
}
if(flag) cnt++;
}
ans = max(ans, cnt);
if(ans == N){
cout << N << '\n';
exit(0);
}
return;
}
for(int i = idx; i < 26; i++){
if(alpha[i]) continue;
alpha[i] = true;
dfs(i, remain - 1);
alpha[i] = false;
}
}
int main(void) {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> N >> K;
string str = "";
for(int i = 0; i < N; i++){
cin >> str;
v.push_back(str.substr(4, str.length() - 8));
}
if(K < 5){
cout << 0 << '\n';
return 0;
}
// a c i n t 필수
alpha[0] = true; alpha[2] = true; alpha[8] = true;
alpha[13] = true; alpha[19] = true;
dfs(0, K-5);
cout << ans << '\n';
return 0;
}