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:A
AndT
Pairing,C
AndG
The 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