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

22.02.17 - [BOJ] 17626. Four Squares #215

Closed
suhyunsim opened this issue Feb 18, 2022 · 0 comments
Closed

22.02.17 - [BOJ] 17626. Four Squares #215

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

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Feb 18, 2022

문제

핵심 아이디어

  • 제곱수일 때 1이 됨: dp[j * j] = 1
  • DP로 제곱수 전후의 변화를 확인하고 풀이

어려운 점, 실수

풀이

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

import java.util.Scanner;

public class Main {
    static int[] dp;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        dp = new int[n + 1];
        dp[0] = 0;
        dp[1] = 1;

        calculate(n);
        System.out.println(dp[n]);
    }

    private static void calculate(int n) {
        for (int i = 2; i <= n; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = 1; j * j <= i; j++) {
                min = Math.min(min, dp[i - j * j]);
            }
            dp[i] = min + 1;
        }
    }
}
@suhyunsim suhyunsim self-assigned this Feb 18, 2022
@suhyunsim suhyunsim added DP 다이나믹 프로그래밍 실버 BOJ - 실버 labels Feb 18, 2022
@suhyunsim suhyunsim added the 성공 맞은 문제 label Feb 18, 2022
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