2764: [JLOI2011] gene complement

Source: Internet
Author: User

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;  }

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.