-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path[BOJ] 1062 가르침(비트마스크, 복습).cpp
More file actions
50 lines (40 loc) · 1.07 KB
/
[BOJ] 1062 가르침(비트마스크, 복습).cpp
File metadata and controls
50 lines (40 loc) · 1.07 KB
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
#include <iostream>
#include <vector>
using namespace std;
int count(int mask, vector<int> &words) {
int cnt = 0;
for (int word : words) {
if ((word & ((1<<26)-1-mask)) == 0) { // 배우지 않은 알파벳이 단어에 있는지 검사
cnt += 1;
}
}
return cnt;
}
int go(int idx, int K, int mask, vector<int> &words) {
if (K < 0) return 0;
if (idx == 26) return count(mask, words);
int ans = 0;
int t1 = go(idx+1, K-1, mask | (1 << idx), words);
if (ans < t1) ans = t1;
if (idx != 'a'-'a' && idx != 'n'-'a' && idx != 't'-'a' && idx != 'i'-'a' && idx != 'c'-'a') {
t1 = go(idx+1, K, mask, words);
if (ans < t1) ans = t1;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int N, K;
cin >> N >> K;
vector<int> words(N);
for (int i = 0; i < N; i++) {
string S;
cin >> S;
for (char x : S) {
words[i] |= (1 << (x - 'a'));
}
}
cout << go(0, K, 0, words) << endl;
return 0;
}