Topic links
The main topic: given a length of n of the base sequence s and a length of m of the base sequence T, now want to complement a certain base in the sequence T to make the sequence s and sequence T pair, the number of solutions
Solution: F[i][j] Indicates long string matching to I, short string matching to J scheme number F[i][j] indicates long string match to I, short string matching to J scheme number
F[I][J]=F[I−1][J], short string + one letter F[i][j]=f[i-1][j], short string + one letter
F[i][j]+=f[i−1][j−1], short and long strings can match f[i][j]+=f[i-1][j-1], short and long strings can match
vigorously high precision
My harvest: Naive
#include <iostream> #include <cstring> #include <cstdio> using namespace std;
#define RAD 100000000 #define B 8 int n,m,p=1,l=0;
Char s1[2005],s2[2005];
struct bi{int s[105],l; Bi () {l=1;}}
F[2][2005];
Bi operator + (bi a,bi b) {bi C;memset (c.s,0,sizeof (C.S));
c.l=a.l>b.l?a.l:b.l;
for (int i=1;i<=c.l;i++) {c.s[i]+=a.s[i]+b.s[i];
if (C.s[i]>=rad) {c.s[i]-=rad;c.s[i+1]++;}
} if (c.s[c.l+1]) c.l++;
return C;
} void Print (Bi a) {printf ("%d", A.S[A.L]), for (int i=a.l-1;i;i--) printf ("%08d", A.s[i]);} BOOL Judge (char A,char b) {return (a== ' a ' &&b== ' T ') | | (a== ' G ' &&b== ' C ') | | (a== ' C ' &&b== ' G ') | |
(a== ' T ' &&b== ' a ');}
void work () {f[0][0].s[1]=1,f[1][0].s[1]=1;
for (int i=1;i<=n;i++,p^=1,l^=1) for (int j=1;j<=m;j++) {f[p][j]=f[l][j];
if (judge (S1[i],s2[j])) f[p][j]=f[p][j]+f[l][j-1];
} print (F[l][m]); } void Init () {scanf ("%d%d%s%s", & n,&m,s1+1,s2+1);
} int main () {init ();
Work ();
return 0; }