Advertisement
a53

A_Lungime_B_Subsir_C_Comun_D_Maximal

a53
May 24th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3. #define NMax 1001
  4. #define maxim(a,b)((a>b)?a:b)
  5. using namespace std;
  6. int M,N;
  7. char A[NMax],B[NMax];
  8. int D[NMax][NMax];
  9.  
  10. int main(void)
  11. {
  12. int i,j;
  13. freopen("lungimesubsircomunmaximal.in","r",stdin);
  14. freopen("lungimesubsircomunmaximal.out","w",stdout);
  15. scanf("%s %s",A,B);
  16. M=strlen(A);
  17. N=strlen(B);
  18. for(i=1;i<=M;++i)
  19. for(j=1;j<=N;++j)
  20. if(A[i-1]==B[j-1])
  21. D[i][j]=1+D[i-1][j-1];
  22. else
  23. D[i][j]=maxim(D[i-1][j],D[i][j-1]);
  24. printf("%d\n",D[M][N]);
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement