标签:back == com AMM 代码 skiing ret error prim
实现代码:
int Longest_increasing_subseq(vector<int> &array){ vector<int> dp(array.size()); dp[0]=-1; int left,right,mid; int count=0; for(int i=0;i<array.size();++i){ left=0; right=count; while(left<=right){ mid = (left+right)/2; if(array[i]<dp[mid]){ right=mid-1; }else if(array[i]>dp[mid]){ left=mid+1; }else{ cout << "case Error happened!\n"; } } if(dp[left]==0){ dp[left]=array[i]; ++count; } else{ dp[left]=min(dp[left],array[i]); } } return count; }
应用于解决问题:https://app.codility.com/programmers/lessons/90-tasks_from_indeed_prime_2015_challenge/slalom_skiing/
SlalomSkiing:
int solution(vector<int> &A){ vector<int> B; int mmax=(*max_element(A.begin(),A.end()))+1; // overturn A to two states, and extend to B as input_Array for (int i=0;i < A.size();++i){ // avoid extend_elements destory A charactor of Increasing subseq in local B.push_back(mmax*2+A[i]); B.push_back(mmax*2-A[i]); B.push_back(A[i]); } return Longest_increasing_subseq(B); }
标签:back == com AMM 代码 skiing ret error prim
原文地址:https://www.cnblogs.com/lzw265/p/12287292.html