yoyoboyss

Untitled

Feb 18th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int NMAX = 1024;
  5.  
  6. ifstream fin("cmlsc.in");
  7. ofstream fout("cmlsc.out");
  8.  
  9. int s1[NMAX], s2[NMAX], vec[NMAX];
  10. int N1, N2, Max;
  11.  
  12. int read(){
  13. fin >> N1 >> N2;
  14. for(int i = 0; i < N1; i++)
  15. fin >> s1[i];
  16. for(int i = 0; i < N2; i++)
  17. fin >> s2[i];
  18. }
  19.  
  20. int LSC(int x, int y, int Max){
  21. if(y < 0){
  22. return LSC(x - Max - 1, N2 - Max - 1, Max);
  23. } else {
  24. if(x < 0){
  25. return Max;
  26. } else {
  27. if(s2[y] == 0){
  28. return LSC(x, y - 1, Max);
  29. } else {
  30. if(s1[x] == s2[y]){
  31. vec[Max] = s1[x];
  32. s2[y] = 0;
  33. return LSC(x - 1, y - 1, Max + 1);
  34. } else {
  35. return LSC(x, y - 1, Max);
  36. }
  37. }
  38. }
  39. }
  40. }
  41.  
  42. int afisare(int v[NMAX], int N){
  43. for(int i = 0; i < N; i++)
  44. fout << v[i] << ' ';
  45. }
  46.  
  47. int main(){
  48.  
  49. read();
  50. Max = LSC(N1 - 1, N2 - 1, 0);
  51. fout << Max << endl;
  52. reverse(vec, vec+Max);
  53. afisare(vec, Max);
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment