fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7.  
  8. const int INF = 1e9;
  9. const ll LINF = 1e18;
  10.  
  11. const int N = 1e3 + 5;
  12.  
  13. int n;
  14. int a[N];
  15. int dp[N]; // dp[i] = Độ dài dãy con tăng dài nhất kết thúc tại i
  16.  
  17. int main() {
  18. ios::sync_with_stdio(false);
  19. cin.tie(nullptr);
  20. cin >> n;
  21. for (int i = 1; i <= n; i++) cin >> a[i];
  22.  
  23. for (int i = 1; i <= n; i++) {
  24. dp[i] = 1; // i đứng một mình
  25. for (int j = 1; j < i; j++) { // ghép i vào sau một dãy con tăng nào đó ở trước
  26. if (a[j] < a[i]) dp[i] = max(dp[i], dp[j] + 1);
  27. }
  28. }
  29.  
  30. int ans = 0;
  31. for (int i = 1; i <= n; i++) {
  32. ans = max(ans, dp[i]);
  33. }
  34.  
  35. cout << ans << '\n';
  36. }
Success #stdin #stdout 0.01s 5280KB
stdin
6
1 2 5 4 6 2
stdout
4