λ¬Έμ
https://www.acmicpc.net/problem/17626
17626λ²: Four Squares
λΌκ·Έλμ£Όλ 1770λ μ λͺ¨λ μμ°μλ λ· νΉμ κ·Έ μ΄νμ μ κ³±μμ ν©μΌλ‘ ννν μ μλ€κ³ μ¦λͺ νμλ€. μ΄λ€ μμ°μλ 볡μμ λ°©λ²μΌλ‘ ννλλ€. μλ₯Ό λ€λ©΄, 26μ 52κ³Ό 12μ ν©μ΄λ€; λν 42 + 32 + 1
www.acmicpc.net
νμ΄
# λ°±μ€ 17626λ² λ¬Έμ - Four Squares
# pypy3
import sys
N = int(sys.stdin.readline())
dp = [0,1]
for i in range(2, N+1):
min_value = 1e9
j = 1
while (j**2) <= i:
min_value = min(min_value, dp[i - (j**2)])
j += 1
dp.append(min_value + 1)
print(dp[N])
DPλ₯Ό νμ©νμλ€.
'ποΈ Algorithm > π© λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
π© [λ°±μ€] [Python] [ꡬν] 1010λ²_λ€λ¦¬ λκΈ° (0) | 2022.11.03 |
---|---|
π© [λ°±μ€] [Python] [ꡬν] 14916λ²_κ±°μ€λ¦ λ_ (0) | 2022.11.03 |
π© [λ°±μ€] [Python] Class3_1620λ²_ λλμΌ ν¬μΌλͺ¬ λ§μ€ν° μ΄λ€μ (0) | 2022.10.31 |
π© [λ°±μ€] [Python] Class3_2407λ²_ μ‘°ν© (0) | 2022.10.31 |
π© [λ°±μ€] [Python] Class3_11727λ²_ 2 x n νμΌλ§ 2 (0) | 2022.10.31 |