File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ import re
2
+
3
+ def count_bit (n ):
4
+ return n % 2 + count_bit (n // 2 ) if n >= 2 else n
5
+
6
+ N , K = map (int , input ().split ())
7
+ words = [set (re .findall (r'[^acnit]' ,input ())) for _ in range (N )]
8
+ union_words = set ()
9
+ for word in words :
10
+ union_words |= word
11
+
12
+ if K < 5 :
13
+ print (0 )
14
+ exit ()
15
+
16
+ K = K - 5
17
+ word_n = len (union_words )
18
+ union_words = list (union_words )
19
+
20
+ #K는 최대로 배울수있는 단어수이다. 만약에 배워야하는 단어의수가 K보다 같거나 작으면 모든 단어를 배울수있다는뜻이다.
21
+ if K >= word_n :
22
+ print (len (words ))
23
+ exit ()
24
+
25
+ #최대로 배울수있는 단어의 수만큼 배운다.
26
+ res = 0
27
+ for i in range (1 << word_n ):
28
+ if count_bit (i ) == K :
29
+ choosen_alpha = set ()
30
+ for j in range (word_n ):
31
+ if i & 1 << j :
32
+ choosen_alpha .add (union_words [j ])
33
+ cnt = 0
34
+ for word in words :
35
+ if word == word & choosen_alpha :
36
+ cnt += 1
37
+ res = max (res , cnt )
38
+
39
+ print (res )
You can’t perform that action at this time.
0 commit comments