Bzoj 2764 [jloi2011] gene completion

Source: Internet
Author: User

Question: http://www.lydsy.com/JudgeOnline/problem.php? Id = 2764

Given a base sequence s with a length of N and a base sequence T with a length of M, we hope to add a certain base to the sequence T to pair the sequence s with the sequence T, the matching rule is:AAndTPairing,CAndGThe number and location of the base to be added are different. 0 <m ≤ n ≤ 2000 .

Question:
We can consider calculating the number of different solutions matching sequence T in sequence S. Using DP can easily solve this problem.
Ling F [I] [J] Indicates the number of schemes from t to J in the first I-bit matching sequence of sequence S. F [I] [J] If not S [I] Match T [J] , Is F [I? 1] [J] . F [I? 1] [J? 1] The final answer is F [N] [m] , DP can be rolled.
Roughly estimate the upper limit of the answer. You can find that the answer exceeds 264 But cannot exceed C (2000,1000) Or smaller, DP can be directly coupled with high precision.

Code:

#include <cstdio>const int maxn = 2001, maxl = 70, mod = 1000000000;struct BigInt{    int len, num[maxl];    void getint(const int &x) { num[len++] = x; }    void Print()    {        printf("%d", num[len - 1]);        for(int i = len - 2; i >= 0; --i)            printf("%9.9d", num[i]);        putchar(‘\n‘);    }    void operator += (const BigInt &x)    {        if(len < x.len) len = x.len;        for(int i = 0; i < len; ++i)        {            num[i] += x.num[i];            if(num[i] >= mod)            {                num[i] -= mod;                ++num[i + 1];            }        }        if(num[len]) ++len;    }} f[maxn];inline bool check(char a, char b){    return a == ‘A‘ && b == ‘T‘ || a == ‘G‘ && b == ‘C‘ || a == ‘C‘ && b == ‘G‘ || a == ‘T‘ && b == ‘A‘;}int n, m;char s[maxn], t[maxn];int main(){    scanf("%d%d%s%s", &n, &m, s, t);    f[0].getint(1);    for(int i = 1; i <= n; ++i)        for(int j = m; j; --j)            if(check(s[i - 1], t[j - 1])) f[j] += f[j - 1];    f[m].Print();    return 0;}

Bzoj 2764 [jloi2011] gene completion

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.