[BOJ] 1062 가르침

Time Lapse : None

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
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <string>

using namespace std;

#define MAXSIZE 50
string word[MAXSIZE];
bool use[26];
int answer=0;
int N, K;
void answer_func(int alpa, int left)
{
int ans=0;
bool in;

if(left==0)
{
for(int i=0; i<N; i++)
{
in=true;
for(int j=0; j<word[i].size(); j++)
{
if(!use[word[i][j]-'a'])
{
in = false;
break;
}
}
if(in)
ans++;
}
answer = max(ans,answer);
return ;
}

for(int i=alpa; i<26; i++)
{
if(!use[i])
{
use[i] = true;
answer_func(i,left-1);
use[i] = false;
}
}
}
int main(void)
{
cin>>N>>K;

if(K<5)
{
cout<<'0'<<endl;
return 0;
}
if(K==26)
{
cout<<N<<endl;
return 0;
}

for(int i=0; i<26; i++)
use[i] = false;

use['a'-'a'] = true;
use['n'-'a'] = true;
use['t'-'a'] = true;
use['i'-'a'] = true;
use['c'-'a'] = true;

for(int i=0; i<N; i++)
{
cin>>word[i];
word[i]=word[i].substr(0,word[i].size()-4);
word[i]=word[i].substr(4,word[i].size());
}

answer_func(0,K-5);
cout<<answer<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/1062/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.