-
Notifications
You must be signed in to change notification settings - Fork 1
/
1062.cc
90 lines (78 loc) · 1.7 KB
/
1062.cc
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef const ll cll;
typedef queue<ll> qll;
typedef queue<pll> qpll;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll> pqpll;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
ll n, k;
vector<pll> v;
ll _search(ll idx, ll num, ll status)
{
if (num > k)
{
return 0;
}
ll result = 0;
if (idx >= 26)
{
for (auto &p : v)
{
if (!(p.first ^ (p.first & status)))
{
result += p.second;
}
}
return result;
}
if (!(status & (1 << idx)))
{
result = max(result, _search(idx + 1, num + 1, status | (1 << idx)));
}
result = max(result, _search(idx + 1, num, status));
return result;
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll genesis = 1;
genesis |= (1 << 'n' - 'a');
genesis |= (1 << 't' - 'a');
genesis |= (1 << 'i' - 'a');
genesis |= (1 << 'c' - 'a');
cin >> n >> k;
for (ll bitMsk = 0, i = 0; i < n; ++i, bitMsk = 0)
{
string s;
cin >> s;
for (auto &c : s)
{
bitMsk |= (1 << (c - 'a'));
}
bool found = false;
for (auto &p : v)
{
if (p.first == bitMsk)
{
++p.second;
found = true;
break;
}
}
if (!found)
{
v.emplace_back(make_pair(bitMsk, 1));
}
}
cout << _search(1, 5, genesis) << "\n";
return 0;
}