fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. int main() {
  6. // your code goes here
  7. string sa = "abc", sb = "adc";
  8. vector<vector<int>> dp(sa.size()+1, vector<int>(sb.size()+1));
  9.  
  10. for (int i=1;i<=sa.size();i++) {
  11. for (int j=1;j<=sb.size();j++) {
  12. if (sa[i-1] == sb[j-1]) {
  13. dp[i][j] = dp[i-1][j-1] + 1;
  14. } else {
  15. dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
  16. }
  17. }
  18. }
  19. cout<<dp[sa.size()][sb.size()]<<endl;
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
2