슈콩

[BOJ] 백준 1931 회의실 배정 본문

Algorithms/Baekjoon

[BOJ] 백준 1931 회의실 배정

shukong 2025. 8. 27. 14:46
주의: 가장 많은 회의를 하게 되는 갯수를 정하는 경우
<-> 가장 오래 회의를 정하는 경우: dp[i] = max(dp[i-1],dp[j] + (end[i]-start[i])) : j는 i 회의와 겹치지 않는 바로 앞 회의를 하는 경우

 

[문제]

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

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Main {
	static class Meeting{
		int start, end;
		Meeting(int start,int end){
			this.start = start;
			this.end = end;
		}
	}
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st;
    	int n = Integer.parseInt(br.readLine());
    	List<Meeting> list = new ArrayList<>();
    	for(int i=0;i<n;i++) {
    		st = new StringTokenizer(br.readLine());
    		int start = Integer.parseInt(st.nextToken());
    		int end = Integer.parseInt(st.nextToken());
    		list.add(new Meeting(start,end));
    	}
    	list.sort((a,b)->{
    		if(a.end==b.end) 
    			return a.start - b.start;
    		else
    			return a.end - b.end;
    	});
    	int result = 0;
    	int time = 0;
    	for(int i=0;i<n;i++) {
    		if(time>list.get(i).start) continue;
    		else 
    			result++;
    		time = list.get(i).end;
    	}
    	System.out.println(result);
    }
}

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

[BOJ] 백준 12865 평범한 배낭  (0) 2025.08.27
[BOJ] 백준 1026 보물  (0) 2025.08.27
[BOJ] 백준 11047 동전 0  (2) 2025.08.27
[BOJ] 백준 9657 돌 게임 3  (4) 2025.08.27
[BOJ] 백준 9655 돌게임  (0) 2025.08.26