Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int c[22],r[22],pos[22],val[22];
  7. // freopen("input.txt", "r", stdin);
  8. //freopen("in.txt","r",stdin);
  9. int main ()
  10. {
  11.     int n;
  12.     cin>>n;
  13.     for(int i=0; i<n;i++)
  14.     {
  15.         cin>>c[i];
  16.         pos[c[i]] = i;
  17.     }
  18.  
  19.     while(cin>>r[0])
  20.     {
  21.         for(int i=1; i<n;i++)
  22.             cin>>r[i];
  23.       //  memset(val,1,sizeof(val));
  24.       for(int i=0; i<n;i++)
  25.         val[i] = 1;
  26.         for(int i=0; i<n;i++)
  27.         {
  28.             for(int j=0; j<i;j++)
  29.             {
  30.                 if(pos[r[i]] > pos[r[j]])
  31.                 {
  32.                     if( (val[j] + 1 ) > val[i] )
  33.                     {
  34.                         val[i] = val[j] + 1;
  35.                     }
  36.  
  37.                 }
  38.             }
  39.  
  40.  
  41.         }
  42.          int max =0;
  43.         for(int i= 0; i<n;i++)
  44.         {
  45.             if(max < val[i])
  46.                 max = val[i];
  47.         }
  48.         cout<<max<<endl;
  49.     }
  50.  
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement