問題

方針
全検索でよい。Bit全検索でもpythonのitertools libraryのcombinationsでも。
解答
#input
from collections import Counter
from itertools import combinations
n, k = map(int, input().split())
s = [[] for _ in range(n)]
for i in range(n):
s[i] = input()
#output
answer = 0
for i in range(1, n+1):
for j in combinations([p for p in range(n)], i):
temp = ""
M = 0
for x in j:
temp += s[x]
temp2 = Counter(temp)
for y in temp2.values():
if y == k:
M += 1
answer = max(answer, M)
print(answer)提出結果
https://atcoder.jp/contests/abc249/submissions/31482119
感想
ちょっとcodeがpoorな気が。時間も結構かかっている。


コメント