-
algospot - lisAlgorithm/알고스팟 2020. 2. 2. 15:531234567891011121314151617181920212223242526272829303132333435363738394041424344454647//algospot - lis#include <iostream>#include <vector>using namespace std;int N;vector<int> v;vector<int> cache;void init(){cin >> N;v = vector<int>(N);cache = vector<int>(N, -1);for(int i = 0; i<N; ++i)cin >> v[i];}int dp(int idx){int& ret = cache[idx];if(ret != -1)return ret;ret = 0;for(int i = idx+1; i<N; ++i)if(v[idx] < v[i])ret = max(ret, dp(i));++ret;return ret;}int main(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);int C; cin >> C;for(int tn = 0; tn<C; ++tn){init();int ans = 0;for(int i = 0; i<N; ++i)ans = max(ans, dp(i));cout << ans << "\n";}}
cs https://www.algospot.com/judge/problem/read/LIS
algospot.com :: LIS
Longest Increasing Sequence 문제 정보 문제 어떤 정수 수열에서 0개 이상의 숫자를 지우면 이 수열의 부분 수열 (subsequence) 를 얻을 수 있다. 예를 들어 10 7 4 9 의 부분 수열에는 7 4 9, 10 4, 10 9 등이 있다. 단, 10 4 7 은 원래 수열의 순서와 다르므로 10 7 4 9 의 부분 수열이 아니다. 어떤 부분 수열이 순증가할 때 이 부분 수열을 증가 부분 수열 (increasing subseque
www.algospot.com
liscache[idx] : idx를 처음으로 하는 수열의 최대 증가 부분 수열의 길이를 저장한다.

'Algorithm > 알고스팟' 카테고리의 다른 글
algospot - pi (0) 2020.02.02 algospot - jlis (0) 2020.02.02 algospot - trianglepath (0) 2020.02.02 algospot - wildcard (0) 2020.02.02 algospot - jumpgame (0) 2020.02.02