https://www.acmicpc.net/problem/11053
문제
내 풀이
import bisect
# 입력
n = int(input()) # 순열의 길이
numlist = list(map(int, input().split())) # 첫 순열
answer = []
for i in range(len(numlist)): # 주어진 순열을 처음부터 끝까지 탐색해가며
print(f'여기{answer}')
if i == 0: # 0일 때 값은 바로 answer에 넣어준다.
answer.append(numlist[0])
# LIS 기법 구현.
else:
if numlist[i] > numlist[i-1]: # 지금 원소가 이전 원소보다 클때, 증가하는 수열이 성립.
# 해당 원소를 answer에 넣기전 적절한 index를 이분탐색으로 알려줌.
a = bisect.bisect_left(answer, numlist[i])
if a > len(answer)-1: # answer안에 있는 element들보다 값이 클 경우
answer.append(numlist[i]) # 맨뒤에 붙혀준다.
else: # 그이외의 경우 적절한 위치의 element의 값을 바꿔준다.
answer[a] = numlist[i]
elif numlist[i] <= numlist[i-1]: # 위와 동일함.
a = bisect.bisect_left(answer, numlist[i])
answer[a] = numlist[i]
print(len(answer))
해설
LIS 기법을 사용하면 된다 해서 구현을 해보았다.
정답 풀이
a,b = input().split() a = int(a) b = int(b) print(a+b) print(a-b) print(a*b) print(int(a/b)) #print(a//b) print(a%b) #print("%d\n%d\n%d\n%d\n%d"%(a+b, a-b, a*b, a/b, a%b))
출처:
해석
'sw사관학교 정글 2기 > 02 이분탐색, 분할정복, 스택, 큐, 우선순위 큐' 카테고리의 다른 글
[스택] 백준 2504번 괄호의 값 with Python3 (0) | 2021.08.16 |
---|---|
[분할정복] 백준 10830번 행렬 제곱 with Python3 ★★ (0) | 2021.08.16 |
[우선순위 큐, 힙] 백준 1715번 카드 정렬하기 with Python3 (0) | 2021.08.16 |
[큐, 시뮬레이션] 백준 3190번 뱀 with Python3 ★ (0) | 2021.08.16 |
[분할정복, 스택] 백준 6549번 히스토그램에서 가장 큰 직사각형 with Python3 ★★★ (0) | 2021.08.14 |
댓글