-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1062.cpp
More file actions
63 lines (57 loc) · 1.11 KB
/
Copy path1062.cpp
File metadata and controls
63 lines (57 loc) · 1.11 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
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int N, K, answer = 0, bit = 0;
vector<string> words;
int getBit(string s)
{
int bit = 0;
for (int i = 4; i < s.length() - 4; i++)
{
bit |= 1 << (s[i] - 'a');
}
return bit;
}
void init()
{
string antic = "antic";
for (int i = 0; i < antic.length(); i++)
{
bit |= 1 << (antic[i] - 'a');
}
}
void dfs(int nowBit, int cnt, int now)
{
if (cnt == K)
{
int count = 0;
for (int i = 0; i < words.size(); i++)
{
int comparedBit = getBit(words[i]);
if ((nowBit | comparedBit) == nowBit)
count++;
}
answer = answer > count ? answer : count;
return;
}
for (int i = now + 1; i < 26; i++)
{
if ((nowBit | (1 << i)) == nowBit)
continue;
dfs(nowBit | (1 << i), cnt + 1, i);
}
}
int main()
{
cin >> N >> K;
words.assign(N, "");
init();
for (int i = 0; i < N; i++)
{
cin >> words[i];
}
dfs(bit, 5, 0);
cout << answer << endl;
return 0;
}