-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1062.cpp
69 lines (63 loc) · 1.05 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
65
66
67
68
69
// 1062. 가르침
// 2019.09.18
// 브루트 포스, 시뮬레이션, 문자열 처리
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int n, k;
int ans;
vector<string> s;
int alpa[26] = { 1,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0 }; // a, c, i, n, t는 무조건 가르쳐야함
// 21개중에 k-5개를 뽑는 함수
void go(int cnt, int start)
{
if (cnt == k - 5)
{
int cnt = 0;
for (int i = 0; i < s.size(); i++)
{
bool flag = true;
// 현재 글자를 읽을 수 있는지 확인
for (int j = 0; j < s[i].size(); j++)
{
if (alpa[s[i][j] - 'a'] == 0)
{
flag = false;
break;
}
}
if (flag)
{
cnt++;
}
}
ans = max(ans, cnt);
return;
}
for (int i = start; i < 26; i++)
{
if (alpa[i] == 0)
{
alpa[i]++;
go(cnt + 1, i + 1);
alpa[i]--;
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
s.resize(n);
for (int i = 0; i < n; i++)
{
cin >> s[i];
}
go(0, 0);
cout << ans << endl;
return 0;
}