Advertisement
Rezaur_Rahman

LDS

Aug 17th, 2019
1,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int n;
  5. char seq[100];
  6.  
  7. int LIS();
  8.  
  9. int main()
  10. {
  11.     printf("Enter sequence size: ");
  12.     scanf("%d",&n);
  13.     printf("Enter the sequence:\n");
  14.     scanf("%s",&seq);
  15.  
  16.     int ans=0;
  17.     ans=LIS();
  18.     printf("LDS: %d\n",ans);
  19.  
  20.     return 0;
  21. }
  22.  
  23. int LIS()
  24. {
  25.     int i,j,lis[n];
  26.     lis[0]=1;
  27.  
  28.     for(i=1;i<n;i++)
  29.     {
  30.         lis[i]=1;
  31.         for(j=0;j<i;j++)
  32.         {
  33.             if(seq[i]<seq[j] && lis[i]<lis[j]+1)
  34.                 lis[i]=lis[j]+1;
  35.         }
  36.     }
  37.  
  38.     int max=0;
  39.     for(i=0;i<n;i++)
  40.         if(lis[i]>max)
  41.             max=lis[i];
  42.  
  43.     return max;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement