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
- 재귀
- 백트래킹
- 다익스트라
- 스택
- XR Interaction Toolkit
- 문자열
- Unreal Engine 5
- Team Fortress 2
- 수학
- 유니온 파인드
- ue5
- 백준
- 트리
- 구현
- 유니티
- 정렬
- BFS
- 시뮬레이션
- 누적 합
- 알고리즘
- 그리디 알고리즘
- DFS
- 우선순위 큐
- 다이나믹 프로그래밍
- c++
- 자료구조
Archives
- Today
- Total
1일1알
백준 18353번 병사 배치하기 C++ 본문
https://www.acmicpc.net/problem/18353
18353번: 병사 배치하기
첫째 줄에 N이 주어진다. (1 ≤ N ≤ 2,000) 둘째 줄에 각 병사의 전투력이 공백을 기준으로 구분되어 차례대로 주어진다. 각 병사의 전투력은 10,000,000보다 작거나 같은 자연수이다.
www.acmicpc.net
가장 긴 증가하는 부분 수열 응용문제
#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 <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n;
vector<int> v;
vector<int> dp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
v = vector<int>(n);
dp = vector<int>(n, 1);
int maxL = 1;
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (v[j] <= v[i]) continue;
dp[i] = max(dp[i], dp[j] + 1);
}
maxL = max(maxL, dp[i]);
}
cout << n - maxL;
}
'알고리즘' 카테고리의 다른 글
백준 17213번 과일 서리 C++ (0) | 2023.03.24 |
---|---|
백준 16397번 탈출 C++ (0) | 2023.03.23 |
백준 1965번 상자넣기 C++ (0) | 2023.03.21 |
백준 14235번 크리스마스 선물 C++ (0) | 2023.03.20 |
백준 12847번 꿀 아르바이트 C++ (0) | 2023.03.19 |