Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5-kjs254 #19

Merged
merged 2 commits into from
Feb 27, 2024
Merged

5-kjs254 #19

merged 2 commits into from
Feb 27, 2024

Conversation

kjs254
Copy link
Member

@kjs254 kjs254 commented Feb 25, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

๋ชจ์Œ์‚ฌ์ „

์™„์ „ํƒ์ƒ‰ ๋ฌธ์ œ๋กœ ๊ธฐ์žฌ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

2h+@

์ดํ‹€ ๋‚ด๋‚ด ๋ถ™์žก๊ณ  ์žˆ๋˜ ๋ฌธ์ œ์ง€๋งŒ ์‹ค์ œ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•œ ์‹œ๊ฐ„์€ 2์‹œ๊ฐ„ ๋‚จ์ง“์ž…๋‹ˆ๋‹ค.

DFS ๋ฌธ์ œ๋ž€ ๊ฑธ ์ผ์ฐ ์•Œ์•˜๋‹ค๋ฉด 1์‹œ๊ฐ„์ฏค ๊ฑธ๋ ธ์„๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค.

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

1. ๋ฌธ์ œํ•ด์„

์‚ฌ์ „์— ์•ŒํŒŒ๋ฒณ ๋ชจ์Œ 'A', 'E', 'I', 'O', 'U'๋งŒ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š”, ๊ธธ์ด 5 ์ดํ•˜์˜ ๋ชจ๋“  ๋‹จ์–ด๊ฐ€ ์ˆ˜๋ก๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์‚ฌ์ „์—์„œ ์ฒซ ๋ฒˆ์งธ ๋‹จ์–ด๋Š” "A"์ด๊ณ , ๊ทธ๋‹ค์Œ์€ "AA"์ด๋ฉฐ, ๋งˆ์ง€๋ง‰ ๋‹จ์–ด๋Š” "UUUUU"์ž…๋‹ˆ๋‹ค.

5๊ฐ€์ง€ ์•ŒํŒŒ๋ฒณ ๋ชจ์Œ์œผ๋กœ ๊ตฌ์„ฑ๋œ ๋ชจ์Œ ์‚ฌ์ „์„ ์ธ๋ฑ์‹ฑํ•˜๋Š” ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.

image

๊ฐ„๋žตํ•˜๊ฒŒ 40๋ฒˆ๊นŒ์ง€ ์‚ฌ์ „์„ ์ž‘์„ฑํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด "AAAUU" ๋ฅผ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์„ ๊ฒฝ์šฐ, 33๋ฒˆ์งธ ์œ„์น˜์ด๋ฏ€๋กœ 33์„ ์ถœ๋ ฅํ•ด์ค๋‹ˆ๋‹ค.

์œ„ ๋ฌธ์ œ๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์œผ๋กœ ํ•ด๊ฒฐํ•ด ๋ณด์•˜์Šต๋‹ˆ๋‹ค.

1. 5์ง„์ˆ˜

  • ์•ŒํŒŒ๋ฒณ ๋ชจ์Œ 'A', 'E', 'I', 'O', 'U'์„ ๊ฐ๊ฐ 0,1,2,3,4, ๋กœ ์น˜ํ™˜ํ•˜์—ฌ 5์ง„์ˆ˜๋กœ ์ ‘๊ทผํ•ด๋ณด์ž ํ•ฉ๋‹ˆ๋‹ค.

image

ํ•˜์ง€๋งŒ 00004 ๋’ค์— 0001์ด ์˜ค๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์ผ๋ฐ˜์ ์ธ ์ˆ˜ ์ฒด๊ณ„๋ฅผ ๋”ฐ๋ผ๊ฐ€์ง€ ์•Š๊ธฐ์— ์ด ๋ฐฉ๋ฒ•์€ ์ข‹์•„ ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

2. ํŠธ๋ฆฌ ๊ตฌ์กฐ

  • ๊ฐ ์•ŒํŒŒ๋ฒณ ๋งˆ๋‹ค ์šฐ์„ ์ˆœ์œ„๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ ํŠธ๋ฆฌ๋ฅผ ์ด์šฉํ•˜์—ฌ ํƒ์ƒ‰ํ•ด๋ด…๋‹ˆ๋‹ค.

image

(ํŠธ๋ฆฌ ๊ทธ๋ฆฌ๊ธฐ ๋„ˆ๋ฌด ์–ด๋ ต๋„ค์š”.. ํ˜น์‹œ ์‰ฝ๊ฒŒ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๋Š” ์ˆ˜๋‹จ์ด ์žˆ์œผ๋ฉด ์•Œ๋ ค์ฃผ์‹ญ์‡ผ ๐Ÿ˜ข )

๋ชจ์Œ 'A', 'E'๋งŒ์„ ๊ฐ€์ง„ ํŠธ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ์ ˆ๋ฐ˜๋งŒ ๊ทธ๋ ค๋ณด์•˜์Šต๋‹ˆ๋‹ค.

"A", "AA", "AAA", ... "AEEEE" ๊นŒ์ง€ ํƒ์ƒ‰ํ•˜๋Š”๋ฐ ํ•œ ์ธต์”ฉ ๋‚ด๋ ค๊ฐ€๋‹ค๊ฐ€ ์˜ฌ๋ผ๊ฐ€๊ณ ๋ฅผ ๋ฐ˜๋ณตํ•˜๋Š” ๊ณผ์ •์—์„œ DFS์™€ ๋งค์šฐ ์œ ์‚ฌํ•˜๋‹ค๋Š” ์ ์„ ์•Œ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

3. DFS

  • ํ•˜๋…ธ์ดํƒ‘ ๋ฌธ์ œ์™€ ๋น„์Šทํ•œ ์œ ํ˜•์œผ๋กœ ์žฌ๊ท€ํ˜•์‹์„ ์ด์šฉํ•œ DFS ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•ด๋ด…๋‹ˆ๋‹ค.

image

9๋ฒˆ์—์„œ 10๋ฒˆ์œผ๋กœ ๋„˜์–ด๊ฐ€๋Š” ๊ฒฝ์šฐ๋ฅผ ์˜ˆ์‹œ๋กœ ๋“ค๊ฒ ์Šต๋‹ˆ๋‹ค.

9๋ฒˆ์€ ๋งˆ์ง€๋ง‰ ๋‹จ์–ด๊ฐ€ U๋กœ ๋๋‚˜๋ฉฐ ๊ธธ์ด๊ฐ€ 5์ด๊ธฐ ๋•Œ๋ฌธ์— 4๋ฒˆ์œผ๋กœ ๋Œ์•„๊ฐ„ ๋’ค "AAAA"๋ฅผ "AAAE"๋กœ ๋ฐ”๊พธ๋Š” ๊ณผ์ •์œผ๋กœ ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค.

33๋ฒˆ์˜ ๊ฒฝ์šฐ์—” ๊ฐ™์€ ๊ณผ์ •์œผ๋กœ 3๋ฒˆ์œผ๋กœ ๋Œ์•„๊ฐ„ ๋’ค "AAA"๋ฅผ "AAE"๋กœ ๋ฐ”๊พธ๋Š” ๊ณผ์ •์œผ๋กœ ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค.

์ด๋ฅผ ์ฝ”๋“œ๋กœ ๊ตฌํ˜„ํ•ด๋ด…์‹œ๋‹ค.



2. ์ˆ˜๋„ ์ฝ”๋“œ

DFS๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

  1. ๋‹จ์–ด์˜ ๊ธธ์ด๊ฐ€ 5๋ณด๋‹ค ์ž‘์„ ๊ฒฝ์šฐ ์‚ฌ์ „์— ์‚ฝ์ž…๋œ๋‹ค. (์ดˆ๊ธฐ์กฐ๊ฑด)
  2. ์‚ฝ์ž…ํ•œ ๋‹จ์–ด์— 'A', 'E', 'I', 'O', 'U'๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋ง๋ถ™์ธ ๋’ค ์žฌ๊ท€ํ•œ๋‹ค.

์ด์— ๋”ฐ๋ผ ์ฝ”๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

def dfs(my_word):
    global dic
    vowel = ['A','E','I','O','U']
    
    if len(my_word)<=5:
        dic.append(my_word)
        
        for v in vowel:
            dfs(my_word + v)

๋ฉ”์ธํ•จ์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

def solution(word):
    global dic
    dic = []
    dfs('')
    answer = dic.index(word)
    return answer

dic ๋ฆฌ์ŠคํŠธ์—๋Š” ์‚ฌ์ „์˜ ๋ชจ๋“  ๋‹จ์–ด๊ฐ€ ์ˆ˜๋ก๋˜๊ณ  ์ธ๋ฑ์‹ฑ๋งŒ ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๋‹จ, ์‚ฌ์ „์€ 1๋ฒˆ๋ถ€ํ„ฐ ์ธ๋ฑ์‹ฑ ๋˜๋ฏ€๋กœ 0๋ฒˆ ์š”์†Œ์— ' '์„ ๋„ฃ์–ด ์ด๋ฅผ ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

์ „์ฒด ์ฝ”๋“œ

def dfs(my_word):
    global dic
    vowel = ['A','E','I','O','U']
    
    if len(my_word)<=5:
        dic.append(my_word)
        
        for v in vowel:
            dfs(my_word + v)

def solution(word):
    global dic
    dic = []
    dfs('')
    answer = dic.index(word)
    return answer



3. ์ถ”๊ฐ€

๊ฒฐ๊ณผ๋ฅผ ์ œ์ถœํ•˜๋ฉด ์‹œ๊ฐ„์ด ์ƒ๊ฐ๋ณด๋‹จ ์˜ค๋ž˜ ๊ฑธ๋ฆฝ๋‹ˆ๋‹ค.

๋งŒ์•ฝ ๋ชจ๋“  ๋‹จ์–ด๋ฅผ ์ง์ ‘ ๋„ฃ์œผ๋ฉด ๋Œ“๊ธ€๊ณผ ๊ฐ™์ด ์†๋„๋Š” ๊ฐ€์žฅ ๋น ๋ฅด์ง€๋งŒ ์ฝ”๋“œ๋กœ ๊ตฌํ˜„ํ•œ ์˜๋ฏธ๊ฐ€ ์ „ํ˜€ ์—†์–ด์ง‘๋‹ˆ๋‹ค ใ…‹ใ…‹ใ…‹

๊ทธ๋ฆฌ๊ณ  ์‹ค์ œ๋กœ ์ด๋ ‡๊ฒŒ ํ‘ธ์‹  ๋ถ„์ด ๋ช‡๋ช… ๊ณ„์‹ญ๋‹ˆ๋‹ค.

image


๋‹ค์Œ๊ณผ ๊ฐ™์ด 5์ง„์ˆ˜ ๊ณ„์‚ฐ๋ฒ•์œผ๋กœ ํ‘ธ๋Š” ์ฝ”๋“œ๊ฐ€ ์ตœ์ ์˜ ๋ชจ๋ฒ” ๋‹ต์•ˆ์ด๋ผ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.
def solution(word):
    answer = 0
    for i, n in enumerate(word):
        answer += (5 ** (5 - i) - 1) / (5 - 1) * "AEIOU".index(n) + 1
    return answer

๋‹ค๋งŒ ์–ด๋–ค ์›๋ฆฌ๋กœ ๋Œ์•„๊ฐ€๋Š”์ง€๋Š” ์•„์ง ์ดํ•ดํ•˜์ง€ ๋ชปํ•˜๊ฒ ๋„ค์š” ๐Ÿ˜ž ๐Ÿ˜ž

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

์žฌ๊ท€๋ฅผ ์ด์šฉํ•˜์—ฌ DFS๋ฅผ ์ฒ˜์Œ ๊ตฌํ˜„ํ•ด๋ณด์•˜๋Š”๋ฐ ๋จธ๋ฆฟ์†์œผ๋กœ ์›๋ฆฌ๋ฅผ ๋– ์˜ฌ๋ฆฌ๊ธฐ๋„ ์‰ฝ์ง€ ์•Š์ง€๋งŒ ์ฝ”๋“œ๋กœ ์ด๋ฅผ ๊ตฌํ˜„ํ•˜๋Š”๊ฒŒ ๋งค์šฐ๋งค์šฐ ์–ด๋ ค์› ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์žฌ๊ท€ ํŠน์„ฑ ์ƒ ์ฝ”๋“œ๊ฐ€ ์งง๋‹ค ๋ณด๋‹ˆ ๋ฟŒ๋“ฏํ•จ์ด ํ”ผ์–ด์˜ค๋ฅด๋„ค์š”.

๋‹ค์Œ์—๋„ ์ฒ˜์Œ ๋„์ „ํ•˜๋Š” ์œ ํ˜•์„ ํ’€์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

@kjs254
Copy link
Member Author

kjs254 commented Feb 25, 2024

PR์ด ๋Šฆ์–ด์ ธ์„œ ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค..

Copy link
Collaborator

@rivkms rivkms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โœ”๏ธ dfs๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ’€์ดํ•˜๋Š” ๊ฒƒ์€ ์ข‹์€ ์ ‘๊ทผ์ด์—ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค!!

โœ”๏ธ 5์ง„์ˆ˜๋กœ ์ฒ˜์Œ์— ์ ‘๊ทผํ•˜์…จ์ง€๋งŒ, ์ €๋Š” 6์ง„์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ A์˜ ๊ฒฝ์šฐ 10000์— ๋Œ€์ž…ํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ณด์•˜์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ์ผ๋ฐ˜์ ์ธ ์ˆ˜ ์ฒด๊ณ„๋ฅผ ๋”ฐ๋ผ๊ฐ€๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ด๊ธฐ์— ๊ทœ์น™์„ ์ฐพ๋Š”๋‹ค๋ฉด ๋ฌธ์ œ๋ฅผ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ์„ ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

โœ”๏ธ ๋งˆ์ง€๋ง‰์— ์ฒจ๋ถ€ํ•ด์ฃผ์‹  ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ ๊ฐ ์ž๋ฆฌ๊ฐ€ ๋ฐ”๋€œ์— ๋”ฐ๋ผ ๋ช‡ ๋ฒˆ์งธ ์ˆซ์ž๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ๋ฐ”๋กœ ์—ฐ์‚ฐํ•˜๋Š” ์ฝ”๋“œ์ธ ๊ฒƒ ๊ฐ™์€๋ฐ, ์œ ์‚ฌํ•œ ํ•ด์„ค์ด ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„ ์ฒจ๋ถ€ํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค. ๐Ÿ“์ฒจ๋ถ€์ž๋ฃŒ
์ด ๋ฐฉ๋ฒ•์œผ๋กœ ํ’€๋ฉด ์‹œ๊ฐ„์ ์ธ ์ธก๋ฉด์—์„œ ๋” ๋น ๋ฅด๊ฒŒ ๋ฌธ์ œ๋ฅผ ํ’€ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๊ธด ํ•˜๋„ค์š”

โœ”๏ธ ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์„ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๊ณ  ์ƒ๊ฐํ•˜์‹  ๋ฐ”๋ฅผ ์ž์„ธํžˆ ์„ค๋ช…ํ•ด์ฃผ์…”์„œ ์ €์—๊ฒŒ๋„ ๋„์›€์ด ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜

Copy link
Collaborator

@mong3125 mong3125 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ €๋„ ์ˆ˜ํ•™์ ์œผ๋กœ ์ ‘๊ทผํ•ด์„œ ํ’€์—ˆ๋Š”๋ฐ ๊ทœ์น™์„ ํŒŒ์•…ํ•˜๋Š๋ผ ์ข€ ์ด๋ฆฌ์ €๋ฆฌ ์˜ˆ์‹œ ๋ช‡๊ฐœ๋ฅผ ๋Œ๋ ค๋ณด๋ฉด์„œ ํ•˜๋Š๋ผ ์ „ ์—„์ฒญ ์˜ค๋ž˜ ๊ฑธ๋ ธ๋„ค์š”. ์ž˜ ๋ดค์Šต๋‹ˆ๋‹น.

DFS ๋ฐฉ๋ฒ•์€ ์—ฌ๊ธฐ ์Šคํ„ฐ๋”” ์ฒ˜์Œ์˜ค๊ณ  ๋ดค๋Š”๋ฐ ์ด๋Ÿฐ ๋ฐฉ๋ฒ•๋„ ์žˆ๊ตฌ๋‚˜ ์ƒˆ๋กœ์šด ์„ธ๊ณ„๋‹ค.. ์‹ถ์—ˆ์Šต๋‹ˆ๋‹ค.

Copy link
Collaborator

@YIM2UL2ET YIM2UL2ET left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํฅ๋ฏธ๋กœ์šด ๋ฌธ์ œ๋„ค์š”. ์‹œ๊ฐ„ ๋‚จ์„ ๋•Œ ํ•œ๋ฒˆ ํ’€์–ด๋ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค.

์ €๋ผ๋ฉด ์•„๋งˆ 6์ง„์ˆ˜๋กœ ๋นˆ์นธ์„ 0์œผ๋กœ ๋งจ ์™ผ์ชฝ๋ถ€ํ„ฐ ๋„ฃ์€ ๋‹ค์Œ์—, A๋ถ€ํ„ฐ U๊นŒ์ง€ 1~6์œผ๋กœ ์น˜ํ™˜ํ•ด์„œ ์ž๋ฆฟ์ˆ˜์— ๋”ฐ๋ฅธ ๊ทœ์น™ ์ฐพ๊ณ  10์ง„์ˆ˜๋กœ ์น˜ํ™˜ํ•ด์„œ ๋‹ต์„ ์–ป๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ํ’€ ๊ฒƒ ๊ฐ™๋„ค์š”. 6์ง„์ˆ˜๋กœ ํ•˜๋ฉด ๊ธ€์ž ์ˆ˜๊ฐ€ ๋ฐ”๋€Œ์–ด๋„ ์ผ๋ฐ˜์ ์ธ ์ˆ˜ ์ฒด๊ณ„๋ฅผ ๋”ฐ๋ผ๊ฐ€๊ธฐ์— ๊ทœ์น™๋งŒ ์ฐพ๋Š”๋‹ค๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

DFS๋ฅผ ์‚ฌ์šฉํ•˜์‹  ํ’€์ด๋Š” ๋„ˆ๋ฌด ๋†€๋ผ์„œ ๊ฐํƒ„ํ–ˆ๋„ค์š”. ์ €๋Š” ์ง„์ˆ˜๋ณ€ํ™˜ ํ’€์ด๋ฐ–์— ๋‹ต์ด ์—†์„ ์ค„ ์•Œ์•˜๋Š”๋ฐ ๋ง์ด์ฃ .. ์ข‹์€ ์•„์ด๋””์–ด ์–ป๊ณ  ๊ฐ‘๋‹ˆ๋‹ค.

@kjs254
Copy link
Member Author

kjs254 commented Feb 27, 2024

โœ”๏ธ dfs๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ’€์ดํ•˜๋Š” ๊ฒƒ์€ ์ข‹์€ ์ ‘๊ทผ์ด์—ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค!!

โœ”๏ธ 5์ง„์ˆ˜๋กœ ์ฒ˜์Œ์— ์ ‘๊ทผํ•˜์…จ์ง€๋งŒ, ์ €๋Š” 6์ง„์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ A์˜ ๊ฒฝ์šฐ 10000์— ๋Œ€์ž…ํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ณด์•˜์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ์ผ๋ฐ˜์ ์ธ ์ˆ˜ ์ฒด๊ณ„๋ฅผ ๋”ฐ๋ผ๊ฐ€๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ด๊ธฐ์— ๊ทœ์น™์„ ์ฐพ๋Š”๋‹ค๋ฉด ๋ฌธ์ œ๋ฅผ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ์„ ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

โœ”๏ธ ๋งˆ์ง€๋ง‰์— ์ฒจ๋ถ€ํ•ด์ฃผ์‹  ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ ๊ฐ ์ž๋ฆฌ๊ฐ€ ๋ฐ”๋€œ์— ๋”ฐ๋ผ ๋ช‡ ๋ฒˆ์งธ ์ˆซ์ž๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ๋ฐ”๋กœ ์—ฐ์‚ฐํ•˜๋Š” ์ฝ”๋“œ์ธ ๊ฒƒ ๊ฐ™์€๋ฐ, ์œ ์‚ฌํ•œ ํ•ด์„ค์ด ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„ ์ฒจ๋ถ€ํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค. ๐Ÿ“์ฒจ๋ถ€์ž๋ฃŒ ์ด ๋ฐฉ๋ฒ•์œผ๋กœ ํ’€๋ฉด ์‹œ๊ฐ„์ ์ธ ์ธก๋ฉด์—์„œ ๋” ๋น ๋ฅด๊ฒŒ ๋ฌธ์ œ๋ฅผ ํ’€ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๊ธด ํ•˜๋„ค์š”

โœ”๏ธ ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์„ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๊ณ  ์ƒ๊ฐํ•˜์‹  ๋ฐ”๋ฅผ ์ž์„ธํžˆ ์„ค๋ช…ํ•ด์ฃผ์…”์„œ ์ €์—๊ฒŒ๋„ ๋„์›€์ด ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜

โœ”๏ธ dfs๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ’€์ดํ•˜๋Š” ๊ฒƒ์€ ์ข‹์€ ์ ‘๊ทผ์ด์—ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค!!

โœ”๏ธ 5์ง„์ˆ˜๋กœ ์ฒ˜์Œ์— ์ ‘๊ทผํ•˜์…จ์ง€๋งŒ, ์ €๋Š” 6์ง„์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ A์˜ ๊ฒฝ์šฐ 10000์— ๋Œ€์ž…ํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ณด์•˜์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ์ผ๋ฐ˜์ ์ธ ์ˆ˜ ์ฒด๊ณ„๋ฅผ ๋”ฐ๋ผ๊ฐ€๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ด๊ธฐ์— ๊ทœ์น™์„ ์ฐพ๋Š”๋‹ค๋ฉด ๋ฌธ์ œ๋ฅผ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ์„ ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

โœ”๏ธ ๋งˆ์ง€๋ง‰์— ์ฒจ๋ถ€ํ•ด์ฃผ์‹  ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ ๊ฐ ์ž๋ฆฌ๊ฐ€ ๋ฐ”๋€œ์— ๋”ฐ๋ผ ๋ช‡ ๋ฒˆ์งธ ์ˆซ์ž๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ๋ฐ”๋กœ ์—ฐ์‚ฐํ•˜๋Š” ์ฝ”๋“œ์ธ ๊ฒƒ ๊ฐ™์€๋ฐ, ์œ ์‚ฌํ•œ ํ•ด์„ค์ด ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„ ์ฒจ๋ถ€ํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค. ๐Ÿ“์ฒจ๋ถ€์ž๋ฃŒ ์ด ๋ฐฉ๋ฒ•์œผ๋กœ ํ’€๋ฉด ์‹œ๊ฐ„์ ์ธ ์ธก๋ฉด์—์„œ ๋” ๋น ๋ฅด๊ฒŒ ๋ฌธ์ œ๋ฅผ ํ’€ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๊ธด ํ•˜๋„ค์š”

โœ”๏ธ ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์„ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๊ณ  ์ƒ๊ฐํ•˜์‹  ๋ฐ”๋ฅผ ์ž์„ธํžˆ ์„ค๋ช…ํ•ด์ฃผ์…”์„œ ์ €์—๊ฒŒ๋„ ๋„์›€์ด ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜

๊ณต๋ฐฑ์„ 0์œผ๋กœ ๋‘๋Š” ๋ฐฉ๋ฒ•๋„ ์ƒ๊ฐํ•ด๋ณด์•˜์–ด์•ผ ํ–ˆ๋„ค์š”. ํ”ผ๋“œ๋ฐฑ ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

๋ณด๋‚ด์ฃผ์‹  ํ•ด์„ค์„ ์ฝ์œผ๋‹ˆ ์ดํ† ๋ก ๊ฐ„๋‹จํ•œ๊ฑธ ์˜ค๋ž˜ ๋ถ™์žก๊ณ  ์žˆ์—ˆ๋„ค์š”. ์—ญ์‹œ ์ˆ˜ํ•™์ ์œผ๋กœ ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ์ด ์ œ์ผ ๊ฐ„๋‹จํ•˜๊ณ  ์„ธ๋ จ๋œ ๋ฐฉ๋ฒ•์ด์—ˆ๋„ค์š”.

์ €๋ฒˆ์— ์˜ฌ๋ ค์ฃผ์‹  PR์ค‘์—์„œ ํ•˜๋…ธ์ดํƒ‘์œผ๋กœ ์ ‘๊ทผํ•˜์‹ ๊ฒŒ ๋– ์˜ฌ๋ผ์„œ ํฐ ๋„์›€์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ^^

@kjs254
Copy link
Member Author

kjs254 commented Feb 27, 2024

์ €๋„ ์ˆ˜ํ•™์ ์œผ๋กœ ์ ‘๊ทผํ•ด์„œ ํ’€์—ˆ๋Š”๋ฐ ๊ทœ์น™์„ ํŒŒ์•…ํ•˜๋Š๋ผ ์ข€ ์ด๋ฆฌ์ €๋ฆฌ ์˜ˆ์‹œ ๋ช‡๊ฐœ๋ฅผ ๋Œ๋ ค๋ณด๋ฉด์„œ ํ•˜๋Š๋ผ ์ „ ์—„์ฒญ ์˜ค๋ž˜ ๊ฑธ๋ ธ๋„ค์š”. ์ž˜ ๋ดค์Šต๋‹ˆ๋‹น.

DFS ๋ฐฉ๋ฒ•์€ ์—ฌ๊ธฐ ์Šคํ„ฐ๋”” ์ฒ˜์Œ์˜ค๊ณ  ๋ดค๋Š”๋ฐ ์ด๋Ÿฐ ๋ฐฉ๋ฒ•๋„ ์žˆ๊ตฌ๋‚˜ ์ƒˆ๋กœ์šด ์„ธ๊ณ„๋‹ค.. ์‹ถ์—ˆ์Šต๋‹ˆ๋‹ค.

์ €๋„ ์ด๋ฒˆ์— DFS๋กœ ์ฒ˜์Œ ์ ‘๊ทผํ•ด๋ณด์•˜๋Š”๋ฐ ํ•œ๋ฒˆ ์ฝ”๋“œ๋ฅผ ์™„์„ฑํ•˜๋ฉด ์ƒ๊ฐ๋ณด๋‹ค ๊ฐ„๋‹จํ•˜๊ณ  ๊ฐ€๋…์„ฑ๋„ ๊ดœ์ฐฎ์Šต๋‹ˆ๋‹ค. ํ•œ๋ฒˆ ์‰ฌ์šด ๋ฌธ์ œ ๋„์ „ํ•ด ๋ณด์‹œ๊ธธ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค!!

@kjs254 kjs254 closed this Feb 27, 2024
@kjs254 kjs254 deleted the 2-kjs254 branch February 27, 2024 18:05
@kjs254 kjs254 restored the 2-kjs254 branch February 27, 2024 18:05
@kjs254 kjs254 reopened this Feb 27, 2024
@kjs254 kjs254 merged commit 25ce19e into AlgoLeadMe:main Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants