ã¾ãã« LIS ãæ±ãããã¨ããåé¡ï¼ï¼
åé¡æ¦è¦
åã®æ´æ°ãããªãæ°å ãä¸ããããããããã®é¨ååã§ãã£ã¦ãç義å調å¢å ã§ãããã®ã®ãã¡ãé¨ååã®é·ãã®æ大å¤ãæ±ããã
å¶ç´
èãããã¨
LIS ãæ±ãããã¨ããåé¡ã ãéã«åãå¶ç´ã ããå®ã¯ ã§è§£ããã®ã ã
以ä¸ã®è¨äºã«è©³ãã解説ããã
ã³ã¼ã
#include <bits/stdc++.h> using namespace std; template<class T> int LIS(vector<T> a, bool is_strong = true) { const T INF = 1<<30; // to be set appropriately int n = (int)a.size(); vector<T> dp(n, INF); for (int i = 0; i < n; ++i) { if (is_strong) *lower_bound(dp.begin(), dp.end(), a[i]) = a[i]; else *upper_bound(dp.begin(), dp.end(), a[i]) = a[i]; } return lower_bound(dp.begin(), dp.end(), INF) - dp.begin(); } int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; ++i) cin >> A[i]; cout << LIS(A) << endl; }