fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. cin>>n;
  8. int List[n];
  9. for(int i = 0; i < n; i++)
  10. {
  11. cin>>List[i];
  12. }
  13. int LIS[n];
  14. for(int i = 0; i < n; i++)
  15. {
  16. LIS[i] = 1;
  17. }
  18.  
  19. for(int i = 1; i < n; i++)
  20. {
  21. for(int j = 0; j < i; j++)
  22. {
  23. if(List[i] > List[j])
  24. {
  25. LIS[i] = max(LIS[i], 1+ LIS[j]);
  26. }
  27. }
  28. }
  29.  
  30. int mx = INT_MIN;
  31. for(int i = 0; i < n; i++)
  32. {
  33. cout<<LIS[i]<<" ";
  34. if(LIS[i] > mx)mx = LIS[i];
  35. }
  36. cout<<endl<<mx<<endl;
  37.  
  38.  
  39.  
  40. }
  41.  
Success #stdin #stdout 0.01s 5284KB
stdin
7                                                                                3 4 -1 0 6 2 3  
stdout
1 2 1 2 3 3 4 
4