fork download
  1. #include <limits.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. int lis( int* a, int N ) {
  5. int *best, i, j, max = INT_MIN;
  6. best = (int*) malloc ( sizeof( int ) * N );
  7. for ( i = 0; i < N; i++ ) best[i] = 1;
  8. for ( i = 1; i < N; i++ )
  9. for ( j = 0; j < i; j++ )
  10. { if ( a[i] > a[j] && best[i] < best[j] + 1 )
  11. { best[i] = best[j] + 1;
  12. if(max < best[i])
  13. max = best[i];}
  14. }
  15. return max;
  16. }
  17. int main(){
  18. int b[] = { 1, 3, 2, 4, 3, 5, 4, 6 }; printf("%d\n", lis( b, 8 ) );}
Success #stdin #stdout 0s 4292KB
stdin
Standard input is empty
stdout
5