title: how to print longest common subsequence?
body: <p>i am learning about lcs and implemented it..but can't find the way to print the longest common subsequence..how to print it??</p>
  
  <p>my lcs code</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include&lt;iostream&gt;
  #include&lt;algorithm&gt;
  #include&lt;cstring&gt;
  #include&lt;cstdio&gt;
  using namespace std;
  int dp[1005][1005];
  char a[1005],b[1005];
  
  int lcs(int x,int y)
  {
     if(x==strlen(a)||y==strlen(b))
       return 0;
     if(dp[x][y]!=-1)
        return dp[x][y];
     else if(a[x]==b[y])
        dp[x][y]=1+lcs(x+1,y+1);
     else
       dp[x][y]=max(lcs(x+1,y),lcs(x,y+1));
     return dp[x][y];
  }
  int main()
  {
     while(gets(a)&amp;&amp;gets(b))
     {
        memset(dp,-1,sizeof(dp));
        int ret=lcs(0,0);
        printf("%d\n",ret);
     }
  }
  </code></pre>