Notice
Recent Posts
Recent Comments
Link
안녕 세상아,
[c++/백준] 11053 가장 긴 증가하는 부분 수열 본문
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
규칙 찾는 다이나믹 프로그래밍은 너무 어려워..
#include <iostream>
#include <algorithm>
using namespace std;
int arr[1001];
int dp[1001];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < n; i++) {
dp[i] = 1;
for (int j = 0; j < i; j++) {
if (arr[i] > arr[j]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
ans = max(ans, dp[i]);
}
cout << ans;
}'백준' 카테고리의 다른 글
| [c++/백준] 11724 연결 요소의 개수 (0) | 2023.06.02 |
|---|---|
| [c++/백준] 1912 연속합 (1) | 2023.06.02 |
| [c++/백준] 1260 DFS와 BFS (0) | 2023.05.17 |
| [c++/백준] 17413 단어 뒤집기 2 (0) | 2023.05.16 |
| [c++/백준] 9461 파도반 수열 (0) | 2023.05.14 |