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
- 투 포인터
- 그래프
- 자료구조
- 백트래킹
- 수학
- 우선순위 큐
- 시뮬레이션
- 문자열
- 그리디 알고리즘
- 유니온 파인드
- Team Fortress 2
- 정렬
- c++
- XR Interaction Toolkit
- 다익스트라
- 알고리즘
- 누적 합
- ue5
- 재귀
- VR
- 구현
- 스택
- DFS
- 트리
- 백준
- 브루트포스
- Unreal Engine 5
- 유니티
- BFS
- 다이나믹 프로그래밍
Archives
- Today
- Total
1일1알
백준 1965번 상자넣기 C++ 본문
https://www.acmicpc.net/problem/1965
1965번: 상자넣기
정육면체 모양의 상자가 일렬로 늘어서 있다. 상자마다 크기가 주어져 있는데, 앞에 있는 상자의 크기가 뒤에 있는 상자의 크기보다 작으면, 앞에 있는 상자를 뒤에 있는 상자 안에 넣을 수가
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 ans = 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);
}
ans = max(ans, dp[i]);
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 16397번 탈출 C++ (0) | 2023.03.23 |
---|---|
백준 18353번 병사 배치하기 C++ (0) | 2023.03.22 |
백준 14235번 크리스마스 선물 C++ (0) | 2023.03.20 |
백준 12847번 꿀 아르바이트 C++ (0) | 2023.03.19 |
백준 17827번 달팽이 리스트 C++ (0) | 2023.03.18 |