stilllHungry's blog

By stilllHungry, history, 7 years ago, In English

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

Full text and comments »

Tags dp, lcs
  • Vote: I like it
  • -18
  • Vote: I do not like it