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 | 29 | 30 |
Tags
- UnrealEngine4
- const
- DirectX11
- NRVO
- algorithm
- Programmers
- 프로그래머스
- 줄 세우기
- 2294
- directx
- IFileDialog
- TObjectPtr
- 오블완
- softeer
- RVO
- Frustum
- RootMotion
- UE5
- baekjoon
- 1563
- C
- winapi
- 백준
- 팰린드롬 만들기
- Unreal Engine5
- GeeksForGeeks
- 언리얼엔진5
- 티스토리챌린지
- UnrealEngine5
- C++
Archives
- Today
- Total
Game Develop
[Algorithm]Baekjoon 18353번 :: 병사 배치하기 본문
https://www.acmicpc.net/problem/18353
18353번: 병사 배치하기
첫째 줄에 N이 주어진다. (1 ≤ N ≤ 2,000) 둘째 줄에 각 병사의 전투력이 공백을 기준으로 구분되어 차례대로 주어진다. 각 병사의 전투력은 10,000,000보다 작거나 같은 자연수이다.
www.acmicpc.net
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <functional>
#include <sstream>
#include <memory.h>
#include <deque>
#include <set>
#include <unordered_map>
#include <stack>
#include <numeric>
using namespace std;
int n;
int arr[2001] = { 0 };
int dp[2001] = { 0 };
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> arr[i];
}
arr[0] = 0x3f3f3f3f;
int maxSoldierCount = 0; // 최대내림차순길이
for (int i = 1; i <= n; ++i)
{
for (int j = i - 1; j >= 0; --j)
{
if (arr[i] < arr[j])
{
dp[i] = max(dp[i], dp[j] + 1);
maxSoldierCount = max(maxSoldierCount, dp[i]);
}
}
}
cout << n - maxSoldierCount;
}
|
cs |
기본적인 LIS문제인데, 오름차순이 아니라 내림차순을 구하는 문제이다.
그러니 arr[0]에 0이 아닌 큰 수를 넣어놓고 시작하면 된다.
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm]Baekjoon 10211번 : Maximum Subarray (0) | 2024.03.20 |
---|---|
[Algorithm]Baekjoon 2482번 : 색상환 (0) | 2024.03.20 |
[Algorithm]Baekjoon 1351번 :: 무한 수열 (0) | 2024.03.19 |
[Algorithm]Baekjoon 1092번 :: 배 (0) | 2024.03.16 |
[Algorithm]Baekjoon 2169번 :: 로봇 조종하기 (0) | 2024.03.12 |