Longest Increasing Subsequence (LIS)

Правка en4, от AmirHoseinEsmailie, 2025-03-19 21:59:10

LIS is about subsequences, not subarrays.

If you want to solve the problem using subarrays, you can refer to this link: https://codeforces.me/problemset/problem/702/A

The LIS algorithm does not work for finding the longest increasing subarray.

The provided code implements the LIS algorithm.

This problem (https://codeforces.me/problemset/problem/264/B) is a good example of the LIS problem.


#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; #define rep(i, start, end) for (int i = start; i < end; i++) #define all(x) x.begin(), x.end() //------------------------------vector----------------------------------- template <typename T> inline void INTPUT_V(vector<T> &v) { rep(i, 0, v.size()) cin >> v[i]; } // -------------------------------------------------------------------------- #define MOD 1000000007 //#include "MyDebuger.cpp" void solve() { int n; cin >> n; vi numbers(n, 0); INTPUT_V(numbers); vector<int> dp(n, 0); rep(i, 0, n) { rep(j, 0, i) { if (numbers[j] < numbers[i] && dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; } } } //debug(dp); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); // cout.tie(0); int t = 1; // cin >> t; rep(i, 0, t) { solve(); } return 0; }

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский AmirHoseinEsmailie 2025-03-19 21:59:10 8
en3 Английский AmirHoseinEsmailie 2025-03-19 21:58:34 8
en2 Английский AmirHoseinEsmailie 2025-03-19 21:57:36 2 Tiny change: 'turn 0;\n}~~~~~\n\n' -> 'turn 0;\n}\n~~~~~\n\n'
en1 Английский AmirHoseinEsmailie 2025-03-19 21:57:10 1619 Initial revision (published)