cgy12306

[백준 BoJ] 1699 - 제곱수의 합 본문

Algorithm/C++

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

cgy12306 2021. 3. 26. 17:53
// https://www.acmicpc.net/problem/1699
// 제곱수의 합
#include<iostream>
#include<algorithm>
using namespace std;

int dp[100001] = { 0, };

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int N;

	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];
}

'Algorithm > C++' 카테고리의 다른 글

[백준 BoJ] 2579 - 계단 오르기  (0) 2021.03.30
C++ String 출력 방식  (0) 2021.03.28
[백준 BoJ] 2504 - 괄호의 값  (0) 2021.03.25
[백준 BoJ] 10845 - 큐  (0) 2021.03.25
[백준 BoJ] 10828 - 스택  (0) 2021.03.25
Comments