티스토리 뷰
문제 링크
https://www.acmicpc.net/problem/11053
11053번: 가장 긴 증가하는 부분 수열
수열 A가 주어졌을 때, 가장 긴 증가하는 부분 수열을 구하는 프로그램을 작성하시오. 예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분 수열은 A = {10, 20, 10, 30, 20, 50} 이
www.acmicpc.net
현재 값이 이전 값보다 크고 현재의 카운트가 이전의 카운트보다 작으면
현재의 카운트는 이전의 카운트+1 이 됩니다.
구현 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#define endl '\n' | |
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr) | |
using namespace std; | |
const int MAX = 1001; | |
int dp[MAX]; | |
int cnt[MAX]; | |
int main(){ | |
fastio; | |
int n; | |
cin >> n; | |
for(int i=1;i<=n;i++) | |
cin >> dp[i]; | |
int max_cnt = 0; | |
for(int i=1;i<=n;i++){ | |
for(int j=1;j<i;j++){ | |
if(dp[i] > dp[j] && cnt[i] < cnt[j]){ | |
cnt[i] = cnt[j]; | |
} | |
} | |
max_cnt = max(max_cnt, ++cnt[i]); | |
} | |
cout << max_cnt << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
a = list(map(int, input().split())) | |
dp = [0 for i in range(n)] | |
for i in range(n): | |
for j in range(i): | |
if a[i] > a[j] and dp[i] < dp[j]: | |
dp[i] = dp[j] | |
dp[i] += 1 | |
print(max(dp)) |
'Coding Test > 백준' 카테고리의 다른 글
[C++] 백준 11722 - 가장 긴 감소하는 부분 수열 (0) | 2020.08.05 |
---|---|
[C++/Python] 백준 11055 - 가장 큰 증가하는 부분 수열 (0) | 2020.08.04 |
[C++/Python] 백준 2156 - 포도주 시식 (0) | 2020.07.30 |
[C++/Python] 백준 9465 - 스티커 (0) | 2020.07.29 |
[C++/Python] 백준 2193 - 이친수 (0) | 2020.07.28 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- C++
- 삼각형 위의 최대 경로 수 세기
- import
- python
- 스파크
- 종만북
- 완전탐색
- 알고스팟
- 합친 lis
- 팰린드롬 구하기
- 2225
- 분할정복
- 코딩인터뷰 완전분석
- 백준
- 삼각형 위의 최대 경로
- microwaving lunch boxes
- HDFS
- Sqoop
- 하둡
- 외발 뛰기
- Jaeha's Safe
- 두니발 박사의 탈옥
- hive
- Django
- 하이브
- 배열과 문자열
- 출전 순서 정하기
- pyspark
- HiveQL
- Hadoop
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함