fork(1) download
  1.  
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <string>
  5. #include <set>
  6. #include <map>
  7. #include <vector>
  8. #include <math.h>
  9.  
  10. typedef long long LL;
  11.  
  12. using namespace std;
  13.  
  14. const int N = 107;
  15.  
  16. string a;
  17. string b;
  18.  
  19. int d[N][N];
  20. int w[N][N];
  21.  
  22. int D(int x, int y)
  23. {
  24. if (x == a.size() || y == b.size())
  25. return 0;
  26.  
  27. int &res = d[x][y];
  28. if (res != -1)
  29. return res;
  30. res = 0;
  31. if (a[x] == b[y])
  32. res = 1 + D(x + 1, y + 1);
  33. {
  34. int t = D(x, y + 1);
  35. if (res < t)
  36. {
  37. res = t;
  38. w[x][y] = 1;
  39. }
  40. }
  41. {
  42. int t = D(x + 1, y);
  43. if (res < t)
  44. {
  45. res = t;
  46. w[x][y] = 2;
  47. }
  48. }
  49. return res;
  50. }
  51.  
  52. string W(int x, int y) {
  53. if (x == a.size() || y == b.size())
  54. return "";
  55. switch (w[x][y])
  56. {
  57. case 0: return a[x] + W(x + 1, y + 1);
  58. case 1: return W(x, y + 1);
  59. case 2: return W(x + 1, y);
  60. }
  61. return "";
  62. }
  63.  
  64. int main()
  65. {
  66. cin >> a >> b;
  67.  
  68. memset(d, 0xFF, sizeof(d));
  69.  
  70. cout << D(0, 0) << "\n";
  71. cout << W(0, 0) << "\n";
  72.  
  73.  
  74. return 0;
  75. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int D(int, int)’:
prog.cpp:24:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (x == a.size() || y == b.size())
                  ^
prog.cpp:24:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (x == a.size() || y == b.size())
                                   ^
prog.cpp: In function ‘std::string W(int, int)’:
prog.cpp:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (x == a.size() || y == b.size())
                  ^
prog.cpp:53:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (x == a.size() || y == b.size())
                                   ^
prog.cpp: In function ‘int main()’:
prog.cpp:68:27: error: ‘memset’ was not declared in this scope
  memset(d, 0xFF, sizeof(d));
                           ^
stdout
Standard output is empty