[BOJ] 1699번 : 제곱수의 합

2024. 9. 3. 21:46Algorithm

1. problem : 

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

 

2. solution 1 :

#include <bits/stdc++.h>
using namespace std;

int n;
int d[100005];

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0); 
    cin >> n;

    for (int i = 1; i <= n; i++) {
        d[i] = i; // 가장 나쁜 경우는 1^2을 i번 사용
        for (int j = 1; j * j <= i; j++) {
            d[i] = min(d[i], d[i - j * j] + 1);
        }
    }

    cout << d[n] << '\n';
    return 0;
}

soure code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x10/solutions/1699.cpp

 

basic-algo-lecture/0x10/solutions/1699.cpp at master · encrypted-def/basic-algo-lecture

바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.

github.com

 

'Algorithm' 카테고리의 다른 글

[BOJ] 1915번 : 가장 큰 정사각형  (0) 2024.09.04
[BOJ] 9084번 : 동전  (0) 2024.09.04
[BOJ] 9251번 : LCS  (0) 2024.09.03
[BOJ] 10844번 : 쉬운 계단 수  (0) 2024.09.03
[BOJ] 14501번 : 퇴사  (0) 2024.09.02