๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿš€ Development/Problem Solving

[์†Œํ”„ํ‹ฐ์–ด softeer] ์ง€๋„ ์ž๋™ ๊ตฌ์ถ•(Lv.2) - ํŒŒ์ด์ฌ(Python)

by Jay Din 2024. 6. 26.
728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

https://softeer.ai/practice/6280

 

Softeer - ํ˜„๋Œ€์ž๋™์ฐจ๊ทธ๋ฃน SW์ธ์žฌํ™•๋ณดํ”Œ๋žซํผ

 

softeer.ai

 

ํ’€์ด

๋ฌธ์ œ๋ฅผ ๋ณด์ž๋งˆ์ž ์™ ์ง€ ๋ชจ๋ฅด๊ฒŒ DP ๋ฌธ์ œ๋ผ๋Š” ๊ฐ์ด ์™€์„œ ์ ํ™”์‹์„ ์„ธ์šฐ๊ธฐ ์œ„ํ•ด ํŒจํ„ด์„ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค.

์ฐพ์€ ๊ทœ์น™

literation ์ถ”๊ฐ€๋œ ์  ๊ฐœ์ˆ˜ ์  ํ•œ์ค„์— ๊ฐœ์ˆ˜ ์ด ์  ๊ฐœ์ˆ˜
0 0 2 4
1 1 3 9
2 2 5 25
3 4 9 81
4 8 17 289

 

1 literation ๊นŒ์ง€ ๋ฆฌ์ŠคํŠธ์— ์ดˆ๊ธฐ๊ฐ’์œผ๋กœ ๋„ˆ์–ด์ค๋‹ˆ๋‹ค.

์ ์ด *2 ๊ทœ์น™์œผ๋กœ ์ถ”๊ฐ€๋˜๊ณ , ์  ํ•œ์ค„์— ๊ฐœ์ˆ˜๋Š” ์ถ”๊ฐ€๋œ ์  ๊ฐœ์ˆ˜+ ๊ทธ์ „์— ์ ํ•œ์ค„์— ๊ฐœ์ˆ˜์ž…๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์  ํ•œ์ค„์— ๊ฐœ์ˆ˜๋ฅผ ์ œ๊ณฑํ•˜๋ฉด ์ด ์  ๊ฐœ์ˆ˜๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค.

๊ทœ์น™

 

๊ทœ์น™ ์ ์šฉํ•œ ์ฝ”๋“œ

import sys

input = sys.stdin.readline

n = int(input())

addLines = [0] * 16
addLines[0] = 0
addLines[1] = 1

answer = [0] * 16
answer[0] = 2
answer[1] = 3


for i in range(2, n+1):
    addLines[i] = addLines[i - 1] * 2
    answer[i] = answer[i - 1] + addLines[i]


print(answer[n]*answer[n])

 

 

 

728x90
๋ฐ˜์‘ํ˜•