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

16-LJEDD2 #64

Merged
merged 2 commits into from
Feb 20, 2024
Merged

16-LJEDD2 #64

merged 2 commits into from
Feb 20, 2024

Conversation

LJEDD2
Copy link
Collaborator

@LJEDD2 LJEDD2 commented Feb 15, 2024

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

๋ฐฑ์ค€ - ๋‹ค์ด๋‚˜๋ฏน ํ”„๋กœ๊ทธ๋ž˜๋ฐ | ํƒ€์ผ ์ฑ„์šฐ๊ธฐ

๋ฌธ์ œ ์„ค๋ช…

  • 3ร—N ํฌ๊ธฐ์˜ ๋ฒฝ์„ 2ร—1, 1ร—2 ํฌ๊ธฐ์˜ ํƒ€์ผ๋กœ ์ฑ„์šฐ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ์ถœ๋ ฅ
  • ์•„๋ž˜ ์˜ˆ์‹œ๋Š” 3x12 ์˜ ๋ฒฝ์„ ํƒ€์ผ๋กœ ์ฑ„์šด ๊ฒƒ
    image

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

์†Œ์š”์‹œ๊ฐ„ 2์‹œ๊ฐ„
(๊ทœ์น™์ฐพ๊ธฐ 20๋ถ„ + ์‹ ์„ธ์šฐ๊ธฐ 30๋ถ„ + ๋ฌธ์ œํ’€๊ธฐ 50๋ถ„ + ํ•ด๊ฒฐx ๋‹ต๋ณด๊ณ  ์ดํ•ด 20๋ถ„)

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

1. ๋ฌธ์ œ ์ง€๋ฌธ ์ฝ๊ธฐ

  • 3๊ฐ€์ง€ ์‚ฌ๊ฐํ˜•์œผ๋กœ ํƒ€์ผ์„ ์ฑ„์›Œ์•ผํ•œ๋‹ค.
  • ์ง€๋‚œ๋ฒˆ ํ’€์—ˆ๋˜ ๋ฌธ์ œ์™€๋Š” ๋‹ฌ๋ฆฌ ์ด๋ฒˆ์—๋Š” ์„ธ๋กœ ๊ธธ์ด๊ฐ€ 3์ธ ์ง์‚ฌ๊ฐํ˜•์ด๋‹ค.

2. ๊ทœ์น™ ์ฐพ๊ธฐ

  • ์ฃผ์–ด์ง„ ์ž…์ถœ๋ ฅ ๊ฒฐ๊ณผ๋ฅผ ์ง์ ‘ ๊ตฌํ•ด๋‚˜๊ฐ€์•ผํ•œ๋‹ค.

  • ์—ญ์‹œ ์™ผ์ชฝ๋ถ€ํ„ฐ ์ฐจ๋ก€๋กœ ํƒ€์ผ์„ ์ฑ„์›Œ๋‚˜๊ฐ€๋ฉฐ ์‹์„ ์„ธ์›Œ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

    • ๊ทธ๋ฆผ์„ ๊ทธ๋ ค๋‚˜๊ฐ€๋‹ค๋ณด๋ฉด N์ด ํ™€์ˆ˜์ธ ๊ฒฝ์šฐ์—๋Š” ํƒ€์ผ์„ ์ฑ„์šธ ์ˆ˜ ์—†๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์—ˆ๋‹ค. (ํƒ€์ผ์ด ์ตœ๋Œ€ ๊ธธ์ด๊ฐ€ 2์ด๊ธฐ ๋•Œ๋ฌธ)
  • 3X2 ๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒฝ์šฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด 3๊ฐ€์ง€ ๊ฒฝ์šฐ์˜ ์ˆ˜๊ฐ€ ์žˆ๋‹ค.
    image

  • 3X4๋ถ€ํ„ฐ ์ƒˆ๋กœ์šด ํŒจํ„ด์˜ ์œ ๋‹ˆํฌํ•œ ๋ฐฐ์—ด์ด ๋“ฑ์žฅํ•˜๊ฒŒ ๋œ๋‹ค.

    • ๋”ฐ๋ผ์„œ 3X2๋กœ 3๊ฐ€์ง€ ํŒจํ„ด์„ ๋งŒ๋“œ๋Š” ๊ฒฝ์šฐ์— +2๋ฅผ ํ•ด์ค€๋‹ค.
    • ์ด ๊ฒฝ์šฐ์˜ ์ˆ˜๋Š” 3 * 3 + 2 = 11๊ฐ€์ง€
  • 3X6 ๋ถ€ํ„ฐ๋Š” 3X4์— 3X2๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒฝ์šฐ๋“ค์ด ์–‘ ์˜†์— ๋ถ™์„ ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค. (n-2์™€ 2์ธ ๋‘ ๋ธ”๋Ÿญ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๊ธฐ ๋•Œ๋ฌธ)

    • 3 x 4์—์„œ 2 ๋งŒํผ ์—ด ๋„ˆ๋น„๋ฅผ ๋Š˜๋ ธ์œผ๋ฏ€๋กœ 3 x 4 ์˜ ๊ฒฝ์šฐ์˜ ์ˆ˜์— 3 x 2๊ฐ€ ๋ถ™๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๊ณฑํ•œ๋‹ค.
    • image
    • 3X2๋ฅผ ๋ถ™์ผ ๋•Œ, ๊ฒน์น˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋งŒ ๊ตฌํ•ด์„œ ๋”ํ•ด์ฃผ๋Š” ๊ฒƒ์„ ์ฃผ์˜ํ•œ๋‹ค.
    • ์ด ๊ฒฝ์šฐ์˜ ์ˆ˜๋Š” 11 * 3 + 3 * 2 + 2 = 41๊ฐ€์ง€๊ฐ€ ๋‚˜์˜จ๋‹ค.
  • 3X8์˜ ๊ฒฝ์šฐ์˜ ์ˆ˜๋Š” 41 * 3 + 11 * 2 + 3 * 2 + 2

  • 3X10์˜ ๊ฒฝ์šฐ์˜ ์ˆ˜๋Š” dp[8]*3 + d[6]*2 + d[4]*2 + d[2]*2 + 2 ๋กœ ๊ตฌํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค.

image

-> ์œ„์˜ ๊ณผ์ •์„ ๊ฑฐ์น˜๋ฉฐ ์ด 3๊ฐ€์ง€ ๊ทœ์น™์„ ์ฐพ๊ณ  ๋ชจ๋‘ ๋”ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ๋œ๋‹ค.

3. ์ „์ฒด ์ฝ”๋“œ

n = int(input())
# dp = [0]*10001

dp = [0]*31
dp[2] = 3

for i in range(4,31,2):
    dp[i] = (dp[i-2] * 3)
    # 4์ผ๋•Œ๋Š” 3x2 0๊ฐœ / 6์ผ๋•Œ๋Š” 3x2๊ฐ€ 3๊ฐ€์ง€ ๊ฒฝ์šฐ * 2๊ฐœ ... 
    for j in range(i-4,0,-2):
        dp[i] += dp[j] * 2
    dp[i] += 2
print(dp[n])

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

Copy link
Collaborator

@Hwangyerin Hwangyerin left a comment

Choose a reason for hiding this comment

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

ํƒ€์ผ๋ง์— ํ•„์š”ํ•œ ๊ฒฝ์šฐ์˜ ์ˆ˜๋„ ์นœ์ ˆํ•˜๊ฒŒ ๊ทธ๋ฆผ์œผ๋กœ ์†์ˆ˜ ๊ทธ๋ ค์ฃผ์…”์„œ ์‰ฝ๊ฒŒ ๋”ฐ๋ผ๊ฐ€๋ฉฐ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
์—ฐํœด์—๋„ ๋‹ฌ๋ฆฌ์‹œ๊ณ ..์ด๋ฒˆ 16์ฐจ์‹œ PR๋„ ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค๐Ÿ€

@@ -0,0 +1,26 @@
# ์†Œ์š”์‹œ๊ฐ„ 2์‹œ๊ฐ„ (๊ทœ์น™์ฐพ๊ธฐ 20๋ถ„ + ์‹ ์„ธ์šฐ๊ธฐ 30๋ถ„ + ๋ฌธ์ œํ’€๊ธฐ 50๋ถ„ + ํ•ด๊ฒฐx ๋‹ต๋ณด๊ณ  ์ดํ•ด 10๋ถ„)
n = int(input())
dp = [0]*10001
Copy link
Collaborator

Choose a reason for hiding this comment

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

๋ฌธ์ œ์˜ n์˜ ๋ฒ”์œ„๋Š” 30์ดํ•˜์ธ๋ฐ ์‚ฌ์‹ค์ƒ dp๋ฆฌ์ŠคํŠธ์˜ ๊ธธ์ด๊ฐ€ 31์ด๋ฉด ์ถฉ๋ถ„ํ•˜์ง€ ์•Š๋‚˜์š”?
๋ฏธ๋ฆฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ๊ธธ์ด 10001๋กœ ๋งŒ๋“œ๋Š”๊ฒŒ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋™์  ๊ณ„ํš๋ฒ•์—์„œ ์“ฐ๋Š” ๋ฐฉ์‹์ธ์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ํ—‰ ๋ฐฐ์—ด ๊ธธ์ด๊ฐ€ 10001๋กœ ์ง€์ •์ด ๋˜์–ด์žˆ์—ˆ๊ตฐ์š”
N์˜ ์ตœ๋Œ€ ๋ฒ”์œ„๋งŒํผ ํ• ๋‹นํ•ด์ฃผ๋Š” ๊ฒƒ์ด ๋งž์Šต๋‹ˆ๋‹ค !

dp = [0] * 31 

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

๊ทธ๋ฆฌ๊ณ  ์ž…๋ ฅ๋ฐ›์€ n์— ๋Œ€ํ•ด์„œ ๋ฒ”์œ„๋ฅผ ์ง€์ •ํ•ด์ค„ ์ˆ˜ ์žˆ๋Š”๋ฐ
n+1์€ 1์ด ์ž…๋ ฅ๋  ๊ฒฝ์šฐ dp[2]๊ฐ€ ์ธ๋ฑ์Šค๋ฅผ ์ดˆ๊ณผํ•˜๊ฒŒ ๋˜๋ฏ€๋กœ n+2๋กœ ์ถฉ๋ถ„ํžˆ ํฌ๊ฒŒ ๋งŒ๋“ค์–ด์ค„ ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค ๐Ÿ˜€
๊ผญ ์ตœ๋Œ€ ๋ฒ”์œ„๋กœ ์ง€์ •ํ•ด์ฃผ์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค.

dp = [0] * (n+2)
dp[2] = 3

for i in range(4,n+1,2):
    dp[i] = (dp[i-2] * 3)
    # 4์ผ๋•Œ๋Š” 3x2 0๊ฐœ / 6์ผ๋•Œ๋Š” 3x2๊ฐ€ 3๊ฐ€์ง€ ๊ฒฝ์šฐ * 2๊ฐœ ... 
    for j in range(i-4,0,-2):
        dp[i] += dp[j] * 2
    dp[i] += 2
print(dp[n])

Copy link
Collaborator

Choose a reason for hiding this comment

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

ํŒŒ์ด์ฌ์ด๋ผ ๋ฒ”์œ„๋ฅผ ์ง€์ •ํ•ด์ฃผ์ง€ ์•Š์•„๋„ ๋˜๋Š”๊ฑฐ๊ตฐ์š”, ์นœ์ ˆํ•œ ๋‹ต๋ณ€ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค:) ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ

@tgyuuAn tgyuuAn removed the request for review from janghw0126 February 20, 2024 10:19
Copy link
Member

@avocado-13 avocado-13 left a comment

Choose a reason for hiding this comment

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

๋ฌธ์ œ๊ฐ€ ๋ณต์žกํ•ด๋ณด์˜€๋Š”๋ฐ ์ •์€๋‹˜์˜ ์†๊ทธ๋ฆผ๊ณผ ์ƒ์„ธํ•œ ์„ค๋ช… ๋•๋ถ„์— ๋ฌธ์ œ ๊ตฌ์กฐํ™”๋ฅผ ์ˆ˜์›”ํžˆ ํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค ๐Ÿ‘๐Ÿป๐Ÿ‘๐Ÿป
์ด๋ฒˆ ์ฐจ์‹œ PR๋„ ์ •๋ง ๊ณ ์ƒ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹คโœจ ๋Šฆ๊ฒŒ ๋ฆฌ๋ทฐ ์ž‘์„ฑํ•ด์„œ ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค โ—‹|๏ฟฃ|_

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.

3 participants