/*
//ABDCDCBABC  CBABCDCDBA   7
最长相同子序列(不需要连续)
采用动态规划DP 二维表 输出最后一个位置就可
*/
#include <iostream> #include <string> using namespace std; int n, m; string a, b; int main() { cin >> a >> b; n = a.size(); m = b.size(); int f[n+1][m+1]; for(int i=0; i<=m; i++){ f[0][i] = 0; } for(int i=0; i<=n; i++){ f[i][0] = 0; } for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) if(a[i-1] == b[j-1]) f[i][j] = f[i-1][j-1] + 1; else f[i][j] = max(f[i-1][j], f[i][j-1]); cout << f[n][m] << endl; for(int i=0; i<=n; i++) for(int j=0; j<=m; j++){ cout<<f[i][j]; if(j%m==0&&j!=0)cout<<endl; } return 0; }

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-16
  • 2021-08-04
  • 2022-12-23
  • 2021-04-16
相关资源
相似解决方案