'PS/inflearn java coding'에 해당되는 글 42건

  1. 2022.04.23 10953
  2. 2022.04.14 최대점수구하기(냅색)
  3. 2022.04.14 동전교환 (냅색)
  4. 2022.04.14 최대길이증가수열
  5. 2022.04.14 계단오르기
  6. 2022.04.14 원더랜드 (최소스패닝트리)
  7. 2022.04.14 Union & Find
  8. 2022.04.14 최대 수입
  9. 2022.04.14 결혼식 (Greedy)
  10. 2022.04.14 회의실배정 (Greedy)
PS/inflearn java coding2022. 4. 23. 10:21

Tip) sc.next() vs sc.nextLine()

nextLine으로 입력을 받을 경우, 5 이후 공백문자가 입력됨

따라서 split 할 때, 오류가 발생함.(주의) 

5 => 개행을 nextLine 으로 입력받음
1,1
2,3
3,4
9,8
5,2

import java.util.Scanner;

class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		
		for ( int i = 0;  i < n ; ++i) {
			String s = sc.next();		
		    String []tmp =  s.split(",");		    
		    System.out.println(Integer.parseInt(tmp[0]) + Integer.parseInt(tmp[1]));
		}
	}
}

'PS > inflearn java coding' 카테고리의 다른 글

최대점수구하기(냅색)  (0) 2022.04.14
동전교환 (냅색)  (0) 2022.04.14
최대길이증가수열  (0) 2022.04.14
계단오르기  (0) 2022.04.14
원더랜드 (최소스패닝트리)  (0) 2022.04.14
Posted by easy16
PS/inflearn java coding2022. 4. 14. 23:26

 

 

 

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

class Main {

	static int m, n, answer;
	static int []dy;

	public static void main(String args[]) throws Exception {
		Main M = new Main();
		Scanner in = new Scanner(System.in);

		n = in.nextInt();		
		m = in.nextInt();
		int [] dy = new int[m+1];
		for (int i = 0 ; i< n; i++) {
			int ps =in.nextInt();
			int pt =in.nextInt();
			
			for ( int j=m; j >= pt; j-- ) {
				dy[j] = Math.max(dy[j], dy[j - pt]+ps);
			}
			
		}		
		System.out.println(dy[m]);
	}

}
ex)
input
5 20
10 5
25 12
15 8
6 3
7 4
output
41

 

 

최대점수표.xlsx
0.01MB

'PS > inflearn java coding' 카테고리의 다른 글

10953  (0) 2022.04.23
동전교환 (냅색)  (0) 2022.04.14
최대길이증가수열  (0) 2022.04.14
계단오르기  (0) 2022.04.14
원더랜드 (최소스패닝트리)  (0) 2022.04.14
Posted by easy16
PS/inflearn java coding2022. 4. 14. 23:13
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

class Main {

	static int m, n, answer;
	static int []dy;

	public static void main(String args[]) throws Exception {
		Main M = new Main();
		Scanner in = new Scanner(System.in);

		n = in.nextInt();
		int []coin = new int[n];
		for ( int i = 0 ; i<n ; i++) {
			coin[i] = in.nextInt();
		}
		m = in.nextInt();
		//dy[i]정의 :  i 금액을 만드는데 드는 최소 동전개수
		//dy[i]는 Integer.MAX로 초기화
		// dy[j] = dy[j - coin[i]] +1         
		dy = new int[m+1];
		
		Arrays.fill(dy, Integer.MAX_VALUE);
		dy[0] = 0;
		for ( int i = 0; i < n; i++) {
			for ( int j = coin[i]; j<=m ; j++) {
				dy[j] = Math.min(dy[j], dy[j - coin[i]]+1);
			}
		}
		
		System.out.println(dy[m]);

	}

}
ex)
input
3
1 2 5
15
output
3

동전교환표.xlsx
0.01MB

'PS > inflearn java coding' 카테고리의 다른 글

10953  (0) 2022.04.23
최대점수구하기(냅색)  (0) 2022.04.14
최대길이증가수열  (0) 2022.04.14
계단오르기  (0) 2022.04.14
원더랜드 (최소스패닝트리)  (0) 2022.04.14
Posted by easy16
PS/inflearn java coding2022. 4. 14. 22:54

 

11053 제출시 반례가 있음

ex)


2 3 4 1 5


4

아래 글 참조

https://easy16.tistory.com/335

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

class Main {

	static int m, n, answer;
	static int []dy;
	public static void main(String args[]) throws Exception {
		Main M = new Main();
		Scanner in = new Scanner(System.in);

		n = in.nextInt();
		int arr[] = new int[n];
		for ( int i = 0 ; i<n ; i++) {
			arr[i] = in.nextInt();
		}
		//n번째 인덱스에서 최대수열길이를 저장
		dy = new int[n];
		
		//첫번째는 자기 자신만 있으므로 1
		dy[0]=1;
		//이후에는 앞의 숫자들 중, 가장 수열의 길이가 긴 부분을 찾아 자기 자신의 길이 +1을 더하면 된다.
		
		for ( int i = 1 ; i < arr.length; i++) {
			int max=0;
			for ( int j=i-1 ; j >=0 ; j--) {				
				if( arr[j] < arr[i] && dy[j] > max) {
					//현재값보다 앞에 있는 수 중, 가장 큰 값을 찾고, 길이를 1증가시킨 값을 저장.
					max = dy[j];
				}
				dy[i] = max + 1;
				answer = Math.max(dy[i], answer);
			}

		}
		
		
		
		System.out.println(answer);
		
	

	}

}
ex)
input
8
5 3 7 8 6 2 9 4
output
4

 

'PS > inflearn java coding' 카테고리의 다른 글

최대점수구하기(냅색)  (0) 2022.04.14
동전교환 (냅색)  (0) 2022.04.14
계단오르기  (0) 2022.04.14
원더랜드 (최소스패닝트리)  (0) 2022.04.14
Union & Find  (0) 2022.04.14
Posted by easy16
PS/inflearn java coding2022. 4. 14. 22:32

전략

 

다이나믹 table을 만든다

 

한번에 1 or 2번씩 올라갈 수 있을 때

1번 계단 오르는 방법 1

2번 계단 오르는 방법 2

 

3번 계단 오르는 방법, 1번계단에서 2칸 오르기 or 2번 계단에서 1칸 오르기

따라서 3번계단 오르는 방법 = 1번 계단오르는 방법 + 2번 계단 오르는 방법

 

4번 계단 오르는 방법, 2번계단에서 2칸 오르기 or 3번 계단에서 1칸 오르기

..

피보나치

 

 

 

class Main {

	static int m, n, answer;
	static int []dy;
	public static void main(String args[]) throws Exception {
		Main M = new Main();
		Scanner in = new Scanner(System.in);

		n = in.nextInt();
		dy = new int[n+1];
		
		dy[1]=1;
		dy[2]=2;
		for (int i =3 ; i <= n; i++) {
			dy[i] =dy[i-2]+dy[i-1];
		}
		
		System.out.println(dy[n]);

	}

}

ex)
input
7
output
21

 

 

'PS > inflearn java coding' 카테고리의 다른 글

동전교환 (냅색)  (0) 2022.04.14
최대길이증가수열  (0) 2022.04.14
원더랜드 (최소스패닝트리)  (0) 2022.04.14
Union & Find  (0) 2022.04.14
최대 수입  (0) 2022.04.14
Posted by easy16
PS/inflearn java coding2022. 4. 14. 21:29

* 크루스칼

 

최소 스패닝 트리의 특성,

1. 회로가 없다. (연결되면 그래프가 된다)

- 회로의 구성여부는 Union & Find로 판단한다.

2. Vertex의 수 -1 == Edge의 수

- 시간복잡도 줄일 경우 사용.

 

 

 

전략,

입력된 정점 정보를 cost기준으로 오름차순 정렬 이후, Union이 아닌 경우 선택한다. 

(cost가 작은 녀석부터 Union이 된다 => 최소 비용)

 

 

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

//원더랜드
//간선을 오름차순 정렬
class Main {

	static int m, n, answer;

	static int[] unf;
	public static int Find(int v) {
		if (v == unf[v]) return v;
		else return unf[v]=Find(unf[v]);
	}
	
	public static void Union ( int a , int b) {
		int fa = Find(a);
		int fb = Find(b);
		if( fa != fb)  unf[fa]=fb;		
	}
	public static void main(String args[]) throws Exception {
		Main M = new Main();
		Scanner in = new Scanner(System.in);
		//도시 개수
		n = in.nextInt();
		//간선개수
		m = in.nextInt();
		ArrayList<Edge> arr = new ArrayList<>();
		unf = new int [n+1];
		
		//유니온 초기화 (자기 자신의 값)
		for (int i = 1 ; i <= n ; i++ ) unf[i] = i;
		for (int i =0 ;  i < m; i++) {
				int a = in.nextInt();
				int b = in.nextInt();
				int c = in.nextInt();
				arr.add( M.new Edge(a, b, c));
		}
		
		//cost에 대해 오름차순 정렬
		Collections.sort(arr);
		
		//회로가 아닌 것만 누적하며 선택
		for ( Edge ob : arr) {
			int fv1 = Find(ob.v1);
			int fv2 = Find(ob.v2);
			

			//서로소 관계일 경우 누적
			if (fv1 != fv2) {
				answer += ob.cost;
				Union(fv1, fv2);
			}
			
		}
		
		System.out.println(answer);
		

	}
	class Edge implements Comparable<Edge>{
		
		int v1;
		int v2;
		int cost;
		Edge( int v1, int v2, int cost){
			this.v1 = v1;
			this.v2 = v2;
			this.cost = cost;
			
		}
		@Override
		public int compareTo(Main.Edge o) {
			return this.cost - o.cost;
		}		
	}
}
ex)
input
9 12
1 2 12
1 9 25
2 3 10
2 8 17
2 9 8
3 4 18
3 7 55
4 5 44
5 6 60
5 7 38
7 8 35
8 9 15
output
196

 

 

 

* Prim 

 

우선순위 큐 사용.

1. 0번 정점에서 출발하는 것으로 가정 => pQ.offer( new Edge(1,0) );

2. 방문하는 vex의 ch리스트를 통해 회로를 차단.

3. 인접 리스트에서 현재 vex의 간선을 pQ에 모두 넣어준다. 

4. pQ에서 가장 cost가 작은 간선을 선택한다 (Greedy 기법) 

5. 결국 cost가 큰 간선들은 모두 버려진다.

 


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

//원더랜드
class Main {

	static int m, n, answer;


	public static void main(String args[]) throws Exception {
		Main M = new Main();
		Scanner in = new Scanner(System.in);
		//도시 개수
		n = in.nextInt();
		//간선개수
		m = in.nextInt();
		
		ArrayList<ArrayList<Edge>> graph = new ArrayList<ArrayList<Edge>>();
		
		for ( int i = 0 ; i <=n; i++) {
			graph.add( new ArrayList<Edge>());
		}
		
		//방문 체크를 위한 배열
		int [] ch = new int[n+1];
		for (int i= 0; i < m ; ++i ) {
			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();
			
			//무방향성 그래프의 인접리스트 생성
			graph.get(a).add(M.new Edge(b, c));
			graph.get(b).add(M.new Edge(a, c));
		}

		PriorityQueue<Edge> pQ = new PriorityQueue<>();
		
		//초기 값을 0번 노드에서 cost 0으로 간주
		pQ.offer(M.new Edge(1, 0));
		
		while(!pQ.isEmpty()) {
			Edge tmp = pQ.poll();
			
			//end vertex
			int ev = tmp.vex;
			if( ch[ev] == 0 ) {
				ch[ev] = 1;
				//비용 누적
				answer += tmp.cost;
				//ev의 인접 리스트를 탐색하여 방문하지 않은 정점을 offer
				for (Edge ob : graph.get(ev)) {
					//이미 선택된 정점은 계산하지 않음.
					if(ch[ob.vex] == 0)  
						pQ.offer(M.new Edge(ob.vex, ob.cost));					
				}
			}
		}
		

		System.out.println(answer);
		

	}
	class Edge implements Comparable<Edge>{
		
		int vex;
		int cost;
		Edge( int vex, int cost){
			this.vex = vex;
			this.cost = cost;			
		}
		@Override
		public int compareTo(Main.Edge o) {
			return this.cost - o.cost;
		}		
	}
}

ex)
input
9 12
1 2 12
1 9 25
2 3 10
2 8 17
2 9 8
3 4 18
3 7 55
4 5 44
5 6 60
5 7 38
7 8 35
8 9 15
output
196

'PS > inflearn java coding' 카테고리의 다른 글

최대길이증가수열  (0) 2022.04.14
계단오르기  (0) 2022.04.14
Union & Find  (0) 2022.04.14
최대 수입  (0) 2022.04.14
결혼식 (Greedy)  (0) 2022.04.14
Posted by easy16
PS/inflearn java coding2022. 4. 14. 21:07
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	static int n;
	static int m;		
	static int answer;
	
	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		
		Main M = new Main();
		n = 8;//;in.nextInt();
		unf =new int [n+1];
		for (int i = 0 ; i <= n ; i++) {
			unf[i] = i;
		}
		/*
		union(1,2);
		union(2,3);
		union(3,4);
		union(4,5);
		union(6,8);
		*/
		
		union(2,1);
		union(3,2);
		union(3,4);
		union(5,4);
		union(8,6);
		
		System.out.println("dump unf");
		for ( int x : unf)
			System.out.print(x+" ");
		System.out.println();
		
		find(1);
		
		find(2);
		
		System.out.println("after find");
		System.out.println("dump unf");
		for ( int x : unf)
			System.out.print(x+" ");
		System.out.println();
		
		
		for (int i = 0 ; i < 5; i++) {
			int fa = find(i);
			int fb = find(i+1);
			if(fa==fb)
				System.out.println(String.format("[%d %d] is union", i, i+1));
			else
				System.out.println(String.format("[%d %d] is non-union", i, i+1));
		}
	
	}
	static int []unf;
	private static int find(int v) {
		if(v == unf[v])
			return unf[v];
		else
			return unf[v]=find(unf[v]);
	}
	
	private static void union(int a, int b) {
		int fa = find(a);
		int fb = find(b);
		if(fa!=fb) 
			unf[fa] = fb;
		
	}

}


output
dump unf
0 4 1 1 4 4 6 7 6 
after find
dump unf
0 4 1 1 4 4 6 7 6 
[0 1] is non-union
[1 2] is union
[2 3] is union
[3 4] is union
[4 5] is union

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

class Main {

	static int m, n, answer;

	static int[] unf;
	public static int Find(int v) {
		if (v == unf[v]) return v;
		else return unf[v]=Find(unf[v]);
	}
	
	public static void Union ( int a , int b) {
		int fa = Find(a);
		int fb = Find(b);
		if( fa != fb)  unf[fa]=fb;		
	}
	public static void main(String args[]) throws Exception {
		Main M = new Main();
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		m = in.nextInt();
		
		unf = new int [n+1];
		
		//start from 1
		for (int i = 1 ; i <= n ; i++ ) unf[i] = i;
		for (int i =1 ;  i<=m; i++) {
				int a = in.nextInt();
				int b = in.nextInt();
				Union(a, b);
		}
		
		int a = in.nextInt();
		int b = in.nextInt();
		int fa = Find(a);
		int fb = Find(b);

		if( fa == fb) System.out.println("YES");
		else System.out.println("NO");
		

	}


}

ex)
input
9 7
1 2
2 3
3 4
1 5
6 7
7 8
8 9
3 8
output
No

 

union : element를 bind시키는 역할

 

find : chain의 최상단 element를 찾아오며 호출된 v의 unf까지 링크를 생성.

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	static int n;
	static int m;		
	static int answer;
	
	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		
		Main M = new Main();
		n = 8;//;in.nextInt();
		unf =new int [n+1];
		for (int i = 0 ; i <= n ; i++) {
			unf[i] = i;
		}
		
		union(1,2);
		union(2,3);
		union(3,4);
		union(4,5);
		union(6,8);
		
		System.out.println("dump unf");
		for ( int x : unf)
			System.out.print(x+" ");
		System.out.println();
		
		find(1);
		
		find(2);
		
		System.out.println("after find");
		System.out.println("dump unf");
		for ( int x : unf)
			System.out.print(x+" ");
		System.out.println();
	
	}
	static int []unf;
	private static int find(int v) {
		if(v == unf[v])
			return unf[v];
		else
			return unf[v]=find(unf[v]);
	}
	
	private static void union(int a, int b) {
		int fa = find(a);
		int fb = find(b);
		if(fa!=fb) 
			unf[fa] = fb;
		
	}

}


output
dump unf
0 2 3 4 5 5 8 7 8 
after find
dump unf
0 2 5 5 5 5 8 7 8

'PS > inflearn java coding' 카테고리의 다른 글

계단오르기  (0) 2022.04.14
원더랜드 (최소스패닝트리)  (0) 2022.04.14
최대 수입  (0) 2022.04.14
결혼식 (Greedy)  (0) 2022.04.14
회의실배정 (Greedy)  (0) 2022.04.14
Posted by easy16
PS/inflearn java coding2022. 4. 14. 19:54

Priority Queue 사용.

 

 

 

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

class Main {

	static int m, n, answer;

	public static void main(String args[]) throws Exception {
		Main M = new Main();
		Scanner in = new Scanner(System.in);
		n = in.nextInt();

		ArrayList<Class> ar = new ArrayList<>();
		int max =0;
		for (int i = 0; i < n; ++i) {
			int m = in.nextInt();
			int d = in.nextInt();
			max = Math.max(max, d);
			ar.add(M.new Class(m, d));
		}


		
		Collections.sort(ar,Collections.reverseOrder());
		
		for ( Class c : ar) {
			System.out.println(String.format("%d %d", c.m, c.d));
		}

		PriorityQueue<Integer> pQ = new PriorityQueue<>(Collections.reverseOrder());
		
		System.out.println("max : "+max);
		int j=0;
		for (int i = max ; i >=1 ; i--) {
			for ( ; j < n ; j++ ) {
				if(ar.get(j).d < i) {
					break;
				}
				pQ.offer(ar.get(j).m);
			}
			if (!pQ.isEmpty()) {
				int m = pQ.poll();
				answer+=m;
			}
			
		}

		System.out.println(answer);

	}

	class Class implements Comparable<Class> {
		int m, d;

		Class(int money, int day) {
			this.m = money;
			this.d = day;
		}

		@Override
		public int compareTo(Main.Class o) {
				return this.d - o.d;
		}

	}

}


ex)
input
6
50 2
20 1
40 2
60 3
30 3
30 1

output
60 3
30 3
50 2
40 2
20 1
30 1

max : 3
150

'PS > inflearn java coding' 카테고리의 다른 글

원더랜드 (최소스패닝트리)  (0) 2022.04.14
Union & Find  (0) 2022.04.14
결혼식 (Greedy)  (0) 2022.04.14
회의실배정 (Greedy)  (0) 2022.04.14
씨름선수( Greedy or 조합 )  (0) 2022.04.14
Posted by easy16
PS/inflearn java coding2022. 4. 14. 17:17

 

 

시간 및 상태의 오름차순으로 정렬한다.

 

=> 입장할 경우 증가, 나갈 경우 감소

 

 

 


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Main {

	static int m, n, answer;

	public static void main(String args[]) throws Exception {
		Main M = new Main();
		Scanner in = new Scanner(System.in);
		n = in.nextInt();

		ArrayList<Schedule> ar = new ArrayList<>();

		for (int i = 0; i < n*2; i++) {
			int t = in.nextInt();
			char s = 'e';
			if (i%2 == 0 )
				s='s';
			ar.add(M.new Schedule(t,s));
		}

		Collections.sort(ar);

		int cnt =0;
		int max = -1;
		for (Schedule sc : ar) {
			//System.out.println(String.format("%c %d", sc.s,sc.t));
			if ( sc.s == 'e')
				cnt--;
			else 
				cnt++;
			
			max = Math.max(max, cnt);
		}

		
		
		System.out.println(max);

	}

	class Schedule implements Comparable<Schedule> {
		int t;
		char s;

		Schedule(int t, char s) {
			this.t = t;
			this.s = s;
		}

		@Override
		public int compareTo(Schedule o) {
			if( this.t == o.t)
				return this.s - o.s;
			return this.t - o.t;
		}
	}

}
ex)
input
5
14 18
12 15
15 20
20 30
5 14

output
s 5
s 12
e 14
s 14
e 15
s 15
e 18
e 20
s 20
e 30
answer
2

'PS > inflearn java coding' 카테고리의 다른 글

Union & Find  (0) 2022.04.14
최대 수입  (0) 2022.04.14
회의실배정 (Greedy)  (0) 2022.04.14
씨름선수( Greedy or 조합 )  (0) 2022.04.14
피자배달거리 (DFS 조합)  (0) 2022.04.14
Posted by easy16
PS/inflearn java coding2022. 4. 14. 16:29

회의 시작 시간과 종료 시간이 주어졌을 때, 최대 회의수 구하는 문제

 

정답 : 

1.

회의가 끝나는 시간을 기준으로 오름차순 정렬한다.

만약 종료되는 시간이 같다면, 시작시간을 기준으로 오름차순 정렬

 

2.

회의시간이 빨리 끝나는 순서대로 겹치지 않도록 카운트 한다.

 


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Main {

	static int m, n, answer;

	public static void main(String args[]) throws Exception {
		Main M = new Main();
		Scanner in = new Scanner(System.in);
		n = in.nextInt();

		ArrayList<Schedule> ar = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			ar.add(M.new Schedule(in.nextInt(), in.nextInt()));
		}

		Collections.sort(ar);
		int cnt = 0;
		int prevEndTime = 0;
		for (Schedule sc : ar) {
			//System.out.println(String.format("%d %d", sc.s,sc.e));
			int start = sc.s;
			int end = sc.e;

			if (prevEndTime <= start) {
				prevEndTime = end;
				cnt++;
			}
		}

		System.out.println(cnt);

	}

	class Schedule implements Comparable<Schedule> {
		int s, e;

		Schedule(int s, int e) {
			this.s = s;
			this.e = e;
		}

		@Override
		public int compareTo(Schedule o) {
			if( this.e == o.e)
				return this.s - o.s;
			return this.e - o.e;
		}
	}

}
ex)
5
5
1 4
2 3
3 5
4 6
5 7
output
3

ex)
input
3
3 3
1 3
2 3
output
2

'PS > inflearn java coding' 카테고리의 다른 글

최대 수입  (0) 2022.04.14
결혼식 (Greedy)  (0) 2022.04.14
씨름선수( Greedy or 조합 )  (0) 2022.04.14
피자배달거리 (DFS 조합)  (0) 2022.04.14
섬나라 아일랜드 (DFS /BFS)  (0) 2022.04.14
Posted by easy16