알고리즘

C++ 알고리즘 - 백준 17626 Four Squares

마루설아 2025. 1. 7. 20:03

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

 

#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

int main(void) {
	/************** C++ Init **************/
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	/************** C++ Init **************/


	int input1;
	vector<int> v;
	v.push_back(0);

	cin >> input1;

	for (int i = 1; i <= input1; i++) {
		v.push_back(v[i - 1] + 1);

		for (int j = 1; j * j <= i; j++) {
			v[i] = min(v[i], v[i - j * j] + 1);
		}
	}

	cout << v[input1];
}