fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n; // size declare
  7. cin>>n; // size input
  8. int List[n]; // array declare with that size
  9. for(int i = 0; i < n; i++) // array input using for loop
  10. {
  11. cin>>List[i];
  12. }
  13.  
  14. // 11111111-11111111-11111111-11111111
  15. // 00000000-00000000-00000000-00000000
  16. // 00000001-00000001-00000001-00000001 = 16843009
  17. //
  18. // 32 ( 4 byte) 8 bit 255 0->128
  19. //
  20. // +1 = 00000001
  21. // 1's = 11111110
  22. // 2's = 1
  23. // -1 = 11111111 (-1)
  24.  
  25.  
  26.  
  27.  
  28. int LIS[n];
  29. memset(LIS, 1, sizeof(LIS));
  30. for(int i = 0; i < n; i++)
  31. {
  32. LIS[i] = 1;
  33. }
  34.  
  35. for(int i = 1; i < n; i++)
  36. {
  37. for(int j = 0; j < i; j++)
  38. {
  39. if(List[j] < List[i])
  40. {
  41. LIS[i] = max(LIS[i], 1+ LIS[j]);
  42. }
  43. }
  44. }
  45. for(int i = 0; i < n; i++)
  46. {
  47. cout<<LIS[i]<<" ";
  48. }
  49. cout<<endl;
  50. int mx = INT_MIN;
  51. for(int i = 0; i < n; i++)
  52. {
  53. if(mx < LIS[i])mx = LIS[i];
  54. }
  55. cout<<"LIS Length = "<<mx<<endl;
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. }
  65.  
Success #stdin #stdout 0.01s 5264KB
stdin
7                                                                           3 4 -1 0 6 2 3 
stdout
1 2 1 2 3 3 4 
LIS Length = 4