Topic transfer: Human Gene Functions
Idea: The deformation of the LCS, defining the state dp[I [j] is the maximum value obtained for the first J characters of the string s before I character string T, then we can get the state transition equation as:
dp[I [j] = max (dp[I [j-1] + f['-'] [t[j]], dp[i-1 [j] + f[s [i] ['-'], dp[i-1][j-1] + F [s [i]] [t [j]]);
AC Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < cmath> #include <queue> #include <stack> #include <vector> #include <map> #include <set > #include <deque> #include <cctype> #define LL long long#define INF 0x7fffffffusing namespace Std;char s[ 105];char t[105];int len1, Len2;int f[105][105];int dp[105][105];void init () {f[' a '] [' a '] = 5; f[' A ' [' C '] = 1; f[' a ' [' G '] =-2; f[' A ' [' T '] =-1; f[' A ' ['-'] = -3;f[' C ' [' a '] =-1; f[' C ' [' C '] = 5; f[' C ' [' G '] =-3; f[' C ' [' T '] =-2; f[' C ' ['-'] = -4;f[' G ' [' A '] =-2; f[' G ' [' C '] =-3; f[' g ' [' g '] = 5; f[' G ' [' T '] =-2; f[' G ' ['-'] = -2;f[' T ' [' A '] =-1; f[' T ' [' C '] =-2; f[' T ' [' G '] =-2; f[' t ' [t '] = 5; f[' T ' ['-'] = -1;f['-' [' A '] =-3; f['-' [' C '] =-4; f['-' [' G '] =-2; f['-' [' T '] =-1;} int main () {init (); int t;scanf ("%d", &t), while (T--) {scanf ("%d%s", &LEN1, S + 1); scanf ("%d%s", &len2, T + 1 );DP [0][0] = 0;for (int i = 1; I < = Len1; i + +) {dp[i][0] = dp[i-1][0] + f[s[i]]['-'];} for (int i = 1; I <= len2; i + +) {Dp[0][i] = dp[0][i-1] + f['-'][t[i]];} for (int i = 1; I <= len1, i + +) {for (int j = 1; J <= Len2; j + +) {int T1 = dp[i][j-1] + f['-'][t[j]];int t2 = dp[i-1 ][J] + f[s[i]]['-'];int t3 = dp[i-1][j-1] + f[s[i]][t[j]];DP [i][j] = max (t1, Max (T2, T3));}} cout << Dp[len1][len2] << Endl;} return 0;}
Poj-1080-human Gene Functions (variant of LCS)