Skip to content

Commit

Permalink
#2 1699번 제곱수의 합
Browse files Browse the repository at this point in the history
  • Loading branch information
leejw-lu committed Jul 28, 2023
1 parent b548be5 commit 98d877b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 동적 프로그래밍/1699_제곱수의 합.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys
read=sys.stdin.readline

N=int(read())
dp=[0]*(N+1)

for i in range(1,N+1):
dp[i]=i #dp=[0,1,2,3,4....N] 초기화
for j in range(1, i):
# 제곱수가 i보다 커지면 멈춤
if j*j > i:
break
if dp[i] > dp[i-j*j] + 1:
dp[i] = dp[i-j*j] + 1 #dp[4-2*2]+1 =1
print(dp[N])

0 comments on commit 98d877b

Please sign in to comment.