[关闭]
@VecMD 2016-07-11T05:14:21.000000Z 字数 1229 阅读 1555

CF 682D

  1. #include <cstdio>
  2. #include <string>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6. const int maxn = 1107;
  7. int n, m, z;
  8. std::string s, t;
  9. int dp[2][maxn][maxn][2];
  10. void debug(int now, int st){
  11. std::cout << " ";
  12. for(int i = 0; i < m; i ++) {
  13. std::cout << t[i] << ' ';
  14. }
  15. std::cout << "\n" <<n << m << "\n";
  16. for(int i = 1; i <= n; i ++){
  17. for(int j = 1; j <= m; j ++){
  18. if(j == 1) std::cout << s[i - 1] << " : ";
  19. std::cout << dp[now][i][j][st] << ' ';
  20. }
  21. std::cout << "\n";
  22. }
  23. std::cout << std::endl;
  24. }
  25. int main()
  26. {
  27. std::cin >> n >> m >> z;
  28. std::cin >> s;
  29. std::cin >> t;
  30. int now = 0, pre = 0, ans = 0;
  31. for(int k = 1; k <= z; k ++){
  32. now = pre ^ 1;
  33. memset(dp[now], 0, sizeof(dp[now]));
  34. for(int i = k; i <= n; i ++){
  35. for(int j = k; j <= m; j ++){
  36. dp[now][i][j][0] = std::max(dp[now][i - 1][j][0], dp[now][i][j - 1][0]);
  37. if(s[i - 1] == t[j - 1]){
  38. dp[now][i][j][1] = std::max(std::max(dp[pre][i - 1][j - 1][0], dp[pre][i - 1][j - 1][1]), dp[now][i - 1][j - 1][1]) + 1;
  39. dp[now][i][j][0] = std::max(dp[now][i][j][0], std::max(dp[pre][i - 1][j - 1][0], dp[pre][i - 1][j - 1][1]) + 1);
  40. }
  41. dp[now][i][j][0] = std::max(dp[now][i][j][0], dp[now][i][j][1]);
  42. ans = std::max(ans, std::max(dp[now][i][j][0], dp[now][i][j][1]));
  43. }
  44. }
  45. pre = now;
  46. }
  47. std::cout << ans << "\n";
  48. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注