[BOJ] 1699 제곱수의 합

Time Lapse :NONE

1699.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <algorithm>
#include <memory.h>
using namespace std;
int dp[100001];
int N;

int main(void) {
memset(dp,0,sizeof(dp));
cin>>N;
for(int i=1;i<=N;i++)
{
dp[i] = i;
for(int j=1;j*j<=i;j++)
{
dp[i] = min(dp[i],dp[i-j*j]+1);
}
}
cout<<dp[N]<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/1699/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.