fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int n;
  7. cin>>n;
  8.  
  9. int a[n];
  10. for(int i=0;i<n;i++)
  11. {
  12. cin>>a[i];
  13. }
  14.  
  15. int DP[n];
  16. for(int i=0;i<n;i++)
  17. {
  18. DP[i]=1;
  19. for(int j=0;j<i;j++)
  20. {
  21. if(a[j] < a[i] && DP[i] < DP[j]+1)
  22. {
  23. DP[i] = DP[j]+1;
  24. }
  25. }
  26. }
  27.  
  28. int maxi =0;
  29. for(int i=0;i<n;i++)
  30. {
  31. if(maxi < DP[i])
  32. {
  33. maxi = DP[i];
  34. }
  35. }
  36.  
  37. cout<<maxi<<endl;
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5288KB
stdin
8
7 3 5 3 6 2 9 8
stdout
4