Post

๐Ÿข ๊ฐ€๋ฅด์นจ

1. ๋ฌธ์ œ ๋งํฌ

1062๋ฒˆ: ๊ฐ€๋ฅด์นจ


2. ์ฝ”๋“œ

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
"""
[1062] ๊ฐ€๋ฅด์นจ

๐Ÿ’› ๋ฌธ์ œ
๋‚จ๊ทน์— ์‚ฌ๋Š” ๊น€์ง€๋ฏผ ์„ ์ƒ๋‹˜์€ ํ•™์ƒ๋“ค์ด ๋˜๋„๋ก์ด๋ฉด ๋งŽ์€ ๋‹จ์–ด๋ฅผ ์ฝ์„ ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋ ค๊ณ  ํ•œ๋‹ค.
๊ทธ๋Ÿฌ๋‚˜ ์ง€๊ตฌ์˜จ๋‚œํ™”๋กœ ์ธํ•ด ์–ผ์Œ์ด ๋…น์•„์„œ ๊ณง ํ•™๊ต๊ฐ€ ๋ฌด๋„ˆ์ง€๊ธฐ ๋•Œ๋ฌธ์—,
๊น€์ง€๋ฏผ์€ K๊ฐœ์˜ ๊ธ€์ž๋ฅผ ๊ฐ€๋ฅด์น  ์‹œ๊ฐ„ ๋ฐ–์— ์—†๋‹ค.

๊น€์ง€๋ฏผ์ด ๊ฐ€๋ฅด์น˜๊ณ  ๋‚œ ํ›„์—๋Š”, ํ•™์ƒ๋“ค์€ ๊ทธ K๊ฐœ์˜ ๊ธ€์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ๋‹จ์–ด๋งŒ์„ ์ฝ์„ ์ˆ˜ ์žˆ๋‹ค.
๊น€์ง€๋ฏผ์€ ์–ด๋–ค K๊ฐœ์˜ ๊ธ€์ž๋ฅผ ๊ฐ€๋ฅด์ณ์•ผ ํ•™์ƒ๋“ค์ด ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜๊ฐ€ ์ตœ๋Œ€๊ฐ€ ๋˜๋Š”์ง€ ๊ณ ๋ฏผ์— ๋น ์กŒ๋‹ค.

๋‚จ๊ทน์–ธ์–ด์˜ ๋ชจ๋“  ๋‹จ์–ด๋Š” "anta"๋กœ ์‹œ์ž‘๋˜๊ณ , "tica"๋กœ ๋๋‚œ๋‹ค.
๋‚จ๊ทน์–ธ์–ด์— ๋‹จ์–ด๋Š” N๊ฐœ ๋ฐ–์— ์—†๋‹ค๊ณ  ๊ฐ€์ •ํ•œ๋‹ค. ํ•™์ƒ๋“ค์ด ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ๋‹จ์–ด์˜ ์ตœ๋Œ“๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

๐Ÿ’š ์ž…๋ ฅ
์ฒซ์งธ ์ค„์— ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜ N๊ณผ K๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.
N์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , K๋Š” 26๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜ ๋˜๋Š” 0์ด๋‹ค.
๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๋‚จ๊ทน ์–ธ์–ด์˜ ๋‹จ์–ด๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.
๋‹จ์–ด๋Š” ์˜์–ด ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ธธ์ด๊ฐ€ 8๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 15๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค.
๋ชจ๋“  ๋‹จ์–ด๋Š” ์ค‘๋ณต๋˜์ง€ ์•Š๋Š”๋‹ค.

๐Ÿ’™ ์ถœ๋ ฅ
์ฒซ์งธ ์ค„์— ๊น€์ง€๋ฏผ์ด K๊ฐœ์˜ ๊ธ€์ž๋ฅผ ๊ฐ€๋ฅด์น  ๋•Œ, ํ•™์ƒ๋“ค์ด ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ๋‹จ์–ด ๊ฐœ์ˆ˜์˜ ์ตœ๋Œ“๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.
"""

from itertools import combinations

# ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜ n, k
n, k = map(int, input().split())

def check(s, cnt):
    global result

    if cnt == k - 5:
        tmp = 0
        for word in words:
            already = 1
            for c in word:
                if not temp[ord(c) - ord('a')]:
                    already = 0
                    break

            if already:
                tmp += 1

        result = max(result, tmp)
        return

    for i in range(s, 26):
        if not temp[i]:
            temp[i] = 1
            check(i, cnt + 1)
            temp[i] = 0

# ์ค‘๋ณต ์ œ๊ฑฐ
for _ in range(n) :
    words = set(input().rstrip())
temp = [0] * 26
result = 0

# ๊ฐ€๋ฅด์น  ๊ธ€์ž์˜ ์ˆ˜๊ฐ€ 5(a, n, t, i, c)๋ณด๋‹ค ์ž‘์€ ๊ฒฝ์šฐ
if k < 5:
    print(0)
elif k == 26:
    print(n)

for c in ('a', 'c', 'i', 'n', 't'):
    temp[ord(c) - ord('a')] = 1

check(0, 0)
print(result)


This post is licensed under CC BY 4.0 by the author.