LCS modified version (longest Common subsequence the longest common sub-sequence)

Source: Internet
Author: User

Title Description

As an intelligence agent, Nova (number 2nd) has a special skill in conveying intelligence. In order to avoid being stolen information, every time he communicates, he sends out two words that others seem to have no meaning, and in fact the signal has been implied. The method of decryption is very simple, respectively, from two sentences to delete any number of letters, so that the remainder of the two sentences the same, through a certain deletion method, you can make the remaining part of the same and the length of the largest, you get the possible signal. There may be a number of password, but also to be screened, now the agency is not enough, I hope you can help, screening work without you to complete, you only need to calculate the password length and number. (Note that the position of the letter is also important information of the password, the location of the letter composed of different letters is not the same, see example)

Input

Multiple sets of test data (fewer than 20 groups)

Each set of data is entered in two rows, each of two strings (with only English letters, no spaces), and each string ends with "."

Output

For each set of data, the output of two lines, the length of the first code, the number of the second code of conduct (the answer may be large, the number of 100000000 modulo)

Input sample
AAAA.AA.
Output sample
26
Title Source: Http://biancheng.love/contest/17/problem/F/index
The implementation of the longest common subsequence can be consulted: http://www.cnblogs.com/huangxincheng/archive/2012/11/11/2764625.html
The difference from the previous one is that you need to figure out how many of the longest common sub-sequences there are! Look at a lot of blogs rarely mention the number of the longest common sub-series
The code implementation is given below:
1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intm=100000000;//the M-modulo5 intf[2][5001]= {0},g[2][5001]= {0};6 7 intMain ()8 {9     strings1,s2;Ten      while(cin>>s1>>S2) One     { AMemset (F,0,sizeof(f)); -Memset (G,0,sizeof(g)); -         intLen1=s1.size ()-1, Len2=s2.size ()-1;//string s1,s2 length the  -  for(intI=0; i<=len2; i++) -g[0][i]=1; -     intK; +      for(intI=1; i<=len1; i++) -     { +K=i &1;//with the operation when I is odd k=1, when I the even number is K is 0 Amemset (G[k],0,sizeof(G[k])); atmemset (F[k],0,sizeof(F[k])); -g[k][0]=1; -g[!k][0]=1; -          for(intj=1; j<=len2; J + +) -         { -             if(s1[i-1]==s2[j-1]) in             { -f[k][j]=f[!k][j-1]+1; tog[k][j]=g[!k][j-1]; +g[k][j]%=m; -                 if(f[k][j]==f[!K] [j]) the                 { *g[k][j]+=g[!K] [j]; $g[k][j]%=m;Panax Notoginseng                 } -                 if(f[k][j-1]==F[k][j]) the                 { +g[k][j]+=g[k][j-1]; Ag[k][j]%=m; the                 } +             } -             Else $             { $                 if(f[!k][j]>f[k][j-1]) -                 { -f[k][j]=f[!K] [j]; theg[k][j]+=g[!K] [j]; -g[k][j]%=m;Wuyi                 } the                 if(f[!k][j]<f[k][j-1]) -                 { Wuf[k][j]=f[k][j-1]; -g[k][j]+=g[k][j-1]; Aboutg[k][j]%=m; $                 } -                 if(f[!k][j]==f[k][j-1]) -                 { -f[k][j]=f[!K] [j]; Ag[k][j]+=g[!k][j]+g[k][j-1]; +                  if(f[!k][j-1]==F[K][J]) g[k][j]-=g[!k][j-1]; theG[k][j]= (g[k][j]+3*M)%m; -                 } $             } the         } the     } thecout<<f[k][len2]<<Endl; thecout<<g[k][len2]<<Endl; -     } in}



LCS modified version (longest Common subsequence the longest common sub-sequence)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.