- 문제 링크 : boj.kr/11568
- 난이도 : S2
- 태그 : DP, LIS
코드
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define INF 0x7FFFFFFF
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector<int> arr(n), dp(n, 0);
for(auto &e : arr) cin >> e;
for(int i = 0; i < n; i++) {
int M = 0;
for(int j = 0; j < i; j++) {
if(arr[j] < arr[i]) M = max(M, dp[j]);
}
dp[i] = M+1;
}
int ans = 0;
for(auto e : dp) ans = max(ans, e);
cout << ans;
return 0;
}
풀이
N이 1000으로 작기 때문에 N^2 LIS로 해결할 수 있다.
728x90
'PS' 카테고리의 다른 글
| BOJ 32749 : 타노수 (0) | 2024.12.21 |
|---|---|
| BOJ 11055 : 가장 큰 증가하는 부분 수열 (1) | 2024.12.20 |
| BOJ 6236 : 용돈 관리 (0) | 2024.12.18 |
| BOJ 9693 : 시파르 (0) | 2024.12.17 |
| BOJ 20006 : 랭킹전 대기열 (0) | 2024.12.16 |