슈콩

[BOJ] 백준 7570 줄 세우기 본문

Algorithms/Baekjoon

[BOJ] 백준 7570 줄 세우기

shukong 2025. 9. 4. 00:41

[문제]

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

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st;
    	int n = Integer.parseInt(br.readLine());
    	int[] dp = new int[n+1];
    	st = new StringTokenizer(br.readLine());
    	int max = 0;
    	for(int i=0;i<n;i++) {
    		int num = Integer.parseInt(st.nextToken());
    		dp[num] = dp[num-1] + 1;
    		max = Math.max(dp[num], max);
    	}
    	System.out.println(n-max);
    }
}

'Algorithms > Baekjoon' 카테고리의 다른 글

[BOJ] 백준 11653 소인수분해  (0) 2025.09.05
[BOJ] 백준 8980 택배  (0) 2025.09.05
[BOJ] 백준 2457 공주님의 정원  (0) 2025.09.04
[BOJ] 백준 2457 공주님의 정원  (0) 2025.09.03
[BOJ] 백준 2170 선 긋기  (0) 2025.08.28