Please read the new rule regarding the restriction on the use of AI tools. ×

Longest Common Subsequence

Revision en1, by stilllHungry, 2017-01-15 02:29:42

hello guys i'm new with dynamic programming this is my code for this problem and i can't understand the reason of having WA

#include <bits/stdc++.h>
using namespace std;
int memory[1002][1002];
int main()
{
    string s1,s2;
    while(cin>>s1>>s2)
    {
        for(int i=1;i<=s1.length();i++)
        {
            for(int j=1;j<=s2.length();j++)
            {
                if (s1[i-1] == s2[j-1])
                    memory[i][j]=memory[i-1][j-1]+1;
                else
                    memory[i][j]=max(memory[i-1][j],memory[i][j-1]);
            }
        }
        cout<<memory[s1.length()][s2.length()]<<'\n';
    }
    return 0;
}

any tips ? thanks in advance

Tags dp, lcs

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English stilllHungry 2017-01-15 02:29:42 904 Initial revision (published)