Pabon_SEC

Containers

Mar 8th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define inf 0x3f3f3f3f
  3.  
  4. using namespace std;
  5.  
  6. int sequence[1005],n;
  7.  
  8. int LisNlogN()
  9. {
  10.     int i;
  11.  
  12.     int I[n+1];
  13.  
  14.     I[0] = -inf;
  15.  
  16.     for(i=1; i<=n; i++)
  17.     {
  18.         I[i] = inf;
  19.     }
  20.  
  21.     int Lislength = 0;
  22.  
  23.     for(i=0; i<n; i++)
  24.     {
  25.         int low,high,mid;
  26.  
  27.         low = 0;
  28.  
  29.         high = Lislength;
  30.  
  31.         while(low<=high)
  32.         {
  33.             mid = (low+high)/2;
  34.  
  35.             if(I[mid]<sequence[i])
  36.             {
  37.                 low = mid + 1;
  38.             }
  39.             else
  40.             {
  41.                 high = mid - 1;
  42.             }
  43.         }
  44.  
  45.         I[low] = sequence[i];
  46.  
  47.         if(Lislength<low)
  48.         {
  49.             Lislength = low;
  50.         }
  51.     }
  52.  
  53.     return Lislength;
  54. }
  55.  
  56. int main()
  57. {
  58.     ios_base::sync_with_stdio(0);
  59.  
  60.     cin.tie(0);
  61.  
  62.     string s;
  63.  
  64.     int test = 0,i,len;
  65.  
  66.     while(cin>>s)
  67.     {
  68.         if(s=="end") break;
  69.  
  70.         len = s.length();
  71.  
  72.         for(i=0;i<len;i++)
  73.         {
  74.             sequence[i] = s[i]-64;
  75.         }
  76.  
  77.         n = len;
  78.  
  79.         cout<<"Case "<<++test<<": "<<LisNlogN()<<"\n";
  80.     }
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment