G2A Many GEOs
SHARE
TWEET

Untitled

a guest Mar 28th, 2020 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ifstream fin("titu.in");
  6.  
  7. int x[30], y[30], m, n, a[30][30] ;
  8.  
  9. int maxim(int x, int y)
  10. {
  11.     if(x>y)
  12.         return x;
  13.     else
  14.         return y;
  15. }
  16.  
  17. void citeste()
  18. {
  19.     fin>>m>>n;
  20.  
  21.     for(int i=1; i<=m; i++)
  22.         fin>>x[i];
  23.  
  24.     for(int i=1;i<=n;i++)
  25.         fin>>y[i];
  26.     fin.close();
  27. }
  28.  
  29. void cmls()
  30. {
  31.     int i, j;
  32.  
  33.     for(i = 0; i<=m; i++)
  34.        a[i][0] = 0;
  35.  
  36.     for(j=0; j<=n; j++)
  37.         a[0][i] = 0;
  38.  
  39.     for(i=1;i<=m;i++)
  40.         for(j=1;j<=n;j++)
  41.         {
  42.             if(x[i]==y[j])
  43.                 a[i][j] = a[i-1][j-1]+1;
  44.             else
  45.             a[i][j] = maxim(a[i-1][j], a[i][j-1]);
  46.         }
  47.     cout<<a[m][n];
  48.  
  49. }
  50. int main()
  51. {
  52.     citeste();
  53.     cmls();
  54.  
  55.     return 0;
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top