[λ°±μ€(BOJ)] 1699λ²: μ κ³±μμ ν© (Dynamic Programming, C++)
DP[1] = min(1, DP[0]+1) = 1
DP[2] = min(2, DP[2-1]+1) = 2
DP[3] = min(3, DP[3-1]+1) = 3
DP[4] = min(4, DP[4-2*2]+1) = 1
DP[5]: 2
DP[6]: 3
DP[7]: 4
DP[8]: 2
DP[9]: 1
DP[10]: 2
DP[11]: 3
#include <stdio.h>
#include <algorithm>
#include <deque>
using namespace std;
int main(){
int N;
scanf("%d", &N);
deque<int> DP(N+1, 0);
for(int i=1; i<=N; i++){
DP[i] = i; // 1λ‘λ§ κ΅¬μ±νμ λ κ°μλ‘ μ΄κΈ°ν
for(int j=1; j*j <= i; j++){
DP[i] = min(DP[i], DP[i-j*j]+1);
}
}
printf("%d", DP[N]);
}