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.22 - [BOJ] 11054. 가장 긴 바이토닉 부분 수열 #143

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

21.07.22 - [BOJ] 11054. 가장 긴 바이토닉 부분 수열 #143

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

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Jul 22, 2021

문제

핵심 아이디어

20210723-160416

어려운 점, 실수

풀이

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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int[] dI = new int[n];
        for (int i = 0; i < n; i++) {
            dI[i] = 1;
            for (int j = 0; j < i; j++) {
                if (a[j] < a[i] && dI[i] < dI[j] + 1) {
                    dI[i] = dI[j] + 1;
                }
            }
        }
        int[] dD = new int[n];
        for (int i = n - 1; i >= 0; i--) {
            dD[i] = 1;
            for (int j = i + 1; j < n; j++) {
                if (a[j] < a[i] && dD[i] < dD[j] + 1) {
                    dD[i] = dD[j] + 1;
                }
            }
        }
        int ans = dI[0] + dD[0] - 1;
        for (int i = 0; i < n; i++) {
            if (ans < dI[i] + dD[i] - 1) {
                ans = dI[i] + dD[i] - 1;
            }
        }
        System.out.println(ans);
    }
}
@suhyunsim suhyunsim self-assigned this Jul 22, 2021
@suhyunsim suhyunsim added DP 다이나믹 프로그래밍 실버 BOJ - 실버 골드 BOJ - 골드 and removed 실버 BOJ - 실버 labels Jul 23, 2021
@suhyunsim suhyunsim added this to the 7월 4주 차 milestone Jul 23, 2021
@suhyunsim suhyunsim added the 성공 맞은 문제 label Jul 23, 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