문제 링크: https://www.acmicpc.net/problem/1062
백준 알고리즘 중급 1/3 541에서 2번째 - 1062번 가르침을 풀어보았다.
풀이: https://coder38611.tistory.com/136
C++
Python
from itertools import combinations
n, k = map(int, input().split())
if k < 5:
print(0)
else:
k -= 5
nece_chars = {'a', 'n', 't', 'i', 'c'}
input_chars = []
alpha = {ky: v for v, ky in enumerate(
(set(map(chr, range(ord('a'), ord('z')+1))) - nece_chars))}
cnt = 0
for _ in range(n):
tmp = 0
for c in set(input())-nece_chars:
tmp |= (1 << alpha[c])
input_chars.append(tmp)
power_by_2 = (2**i for i in range(21))
for comb in combinations(power_by_2, k):
test = sum(comb)
ct = 0
for cb in input_chars:
if test & cb == cb:
ct += 1
cnt = max(cnt, ct)
print(cnt)
Java
'코테용 문제풀이 > 백준' 카테고리의 다른 글
2048 (Easy) 풀이 (0) | 2023.02.22 |
---|---|
구슬 탈출 2 풀이 (0) | 2023.02.22 |
알파벳 풀이 (0) | 2023.02.22 |
스도미노쿠 풀이 (1) | 2023.02.22 |
스도쿠 풀이 (0) | 2023.02.22 |