본문으로 바로가기

#include<bits/stdc++.h>
using namespace std;
int dp[1001];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n;
	cin >> n;
	vector<int> v1(n);
	for (int i = 0; i < n; i++) {
		cin >> v1[i];
	}
	int ans = 0;

	for (int i = 0; i < n; i++) {
		dp[i] = 1;
		for (int j = 0; j < i; j++) {
			if (v1[j] > v1[i]) {
				dp[i] = max(dp[i],  dp[j]+1);
			}
		}
		ans = max(ans, dp[i]);
	}
	cout << ans;
}

 

DP[I] I번을 마지막으로 하는 가장 작은 수열의 가장 긴 길이가 저장된다.