[BOJ] 2643 색종이 올려 놓기

Time Lapse :10min 2sec

2643.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <stdlib.h>
struct paper{
int garo;
int sero;
};
int compare(const void *a, const void *b){
paper A = *(paper*)a;
paper B = *(paper*)b;
if(A.garo==B.garo)
return A.sero > B.sero ? 1 : -1;
return A.garo > B.garo ? 1 : -1;
}
void swap(int *a, int *b){
int temp = *a;
*a = *b;
*b = temp;
}
int main(void){
int N,answer = 0, DP[100]={[0 ... 99] = 1};
paper P[100];
scanf("%d",&N);
for(int i=0;i<N;i++){
scanf("%d %d",&P[i].garo,&P[i].sero);
if(P[i].sero>P[i].garo) swap(&P[i].garo,&P[i].sero);
}
qsort(P,N,sizeof(paper),compare);
for(int i = 0; i < N; i++){
for(int j = i -1; j >= 0 ; j--)
if(P[j].garo<=P[i].garo&&P[j].sero<=P[i].sero&&DP[j]+1>DP[i]) DP[i] = DP[j]+1;
answer = answer > DP[i]? answer : DP[i];
}
printf("%d",answer);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2643/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.