Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 브루트포스
- 누적 합
- VR
- 수학
- DFS
- 그리디 알고리즘
- 그래프
- 자료구조
- 알고리즘
- Unreal Engine 5
- 유니티
- 백준
- Team Fortress 2
- 문자열
- 투 포인터
- XR Interaction Toolkit
- 우선순위 큐
- c++
- 유니온 파인드
- 백트래킹
- 스택
- 시뮬레이션
- 재귀
- 트리
- 정렬
- 다이나믹 프로그래밍
- 다익스트라
- BFS
- ue5
- 구현
Archives
- Today
- Total
1일1알
백준 2631번 줄세우기 C++ 본문
전체 아이들의 수에서 가장 긴 증가하는 부분 수열의 수를 빼면 된다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
vector<int> dp(n, 1);
int max_length = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (v[j] < v[i]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
max_length = max(max_length, dp[i]);
}
cout << n - max_length;
};
'알고리즘' 카테고리의 다른 글
백준 13023번 ABCDE C++ (0) | 2022.03.14 |
---|---|
백준 14226번 이모티콘 C++ (0) | 2022.03.13 |
백준 4158번 CD C++ (0) | 2022.03.11 |
백준 14246번 k보다 큰 구간 C++ (0) | 2022.03.10 |
백준 2118번 두 개의 탑 C++ (0) | 2022.03.09 |