Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21.07.16 - [BOJ] 1699. 제곱수의 합 #133

Closed
suhyunsim opened this issue Jul 16, 2021 · 0 comments
Closed

21.07.16 - [BOJ] 1699. 제곱수의 합 #133

suhyunsim opened this issue Jul 16, 2021 · 0 comments
Assignees
Labels
DP 다이나믹 프로그래밍 성공 맞은 문제 실버 BOJ - 실버

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

  • D[N] = N을 제곱수의 합으로 나타낼 때의 항의 최소 개수
  • D[i] = min(D[i - j^2] + 1) (1 <= i <= j^2)

어려운 점, 실수

풀이

package main.java.com.poogle.BOJ.Q1699;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            d[i] = i;
            for (int j = 1; j * j <= i; j++) {
                if (d[i] > d[i - j * j] + 1) {
                    d[i] = d[i - j * j] + 1;
                }
            }
        }
        System.out.println(d[n]);
    }
}
@suhyunsim suhyunsim added 실버 BOJ - 실버 DP 다이나믹 프로그래밍 labels Jul 16, 2021
@suhyunsim suhyunsim added this to the 7월 3주 차 milestone Jul 16, 2021
@suhyunsim suhyunsim self-assigned this Jul 16, 2021
@suhyunsim suhyunsim added the 성공 맞은 문제 label Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DP 다이나믹 프로그래밍 성공 맞은 문제 실버 BOJ - 실버
Projects
None yet
Development

No branches or pull requests

1 participant