BOJ[백준] - 1699 - 제곱수의 합

Posted by ceyx
2017. 7. 15. 01:45 Algorithm 문제풀이/BOJ [백준] 문제풀이

https://www.acmicpc.net/problem/1699

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <cstdio>
 
int dp[100001];
int main()
{
   int n;
   scanf("%d"&n);
   for (int i = 1; i <= n; i++) {
      dp[i] = i;
      for (int j = 1; j*<= i; j++) {
         if (dp[i] > dp[i - j*j] + 1) {
            dp[i] = dp[i - j*j] + 1;
         }
      }
   }
   printf("%d", dp[n]);
   return 0;
}
cs