cgy12306
[백준 BoJ] 17626 - Four Squares 본문
// https://www.acmicpc.net/problem/17626
// Four Squares
#include<iostream>
#include<algorithm>
using namespace std;
int dp[50001] = { 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] 7576 - 토마토 (0) | 2021.06.30 |
---|---|
[백준 BoJ] 17219 - 비밀번호 찾기 (0) | 2021.06.30 |
[백준 BoJ] 1012 - 유기농 배추 (0) | 2021.06.30 |
[백준 BoJ] 2606 - 바이러스 (0) | 2021.06.29 |
[백준 BoJ] 1654 - 랜선 자르기 (0) | 2021.06.29 |
Comments