Lcs.
1 /*1243*/2#include <cstdio>3#include <cstring>4#include <cstdlib>5 6 #defineMAXN 20257 #defineMAXM 2568 9 CharTYPE[MAXM];Ten intPOINT[MAXM]; One A CharBULLET[MAXN]; - CharKBFZ[MAXN]; - intDP[MAXN][MAXN]; the intN; - - intMinintAintb) { - returnA<b?a:b; + } - + intMaxintAintb) { A returnA>b?a:b; at } - - intAbsintx) { - returnx<0? -x:x; - } - in intMain () { - intI, J, K; to intL1, L2; + - #ifndef Online_judge theFreopen ("data.in","R", stdin); * #endif $ Panax Notoginseng while(SCANF ("%d", &n)! =EOF) { -memset (Point,0,sizeof(point)); thescanf"%s", type); + for(i=0; i<n; ++i) { Ascanf"%d", &k); thePoint[type[i]] =K; + } -scanf"%s", bullet+1); $scanf"%s", kbfz+1); $L1 = strlen (bullet+1); -L2 = strlen (kbfz+1); - for(i=0; I<=max (L1, L2); ++i) { thedp[0][i] =0; -dp[i][0] =0;Wuyi } the for(i=1; i<=l1; ++i) { - for(j=1; j<=l2; ++j) { Wu if(Bullet[i] = =Kbfz[j]) { -DP[I][J] = dp[i-1][j-1] +Point[bullet[i]]; About}Else { $k = Max (dp[i-1][J], dp[i][j-1]); -DP[I][J] = max (k, dp[i-1][j-1]); - } - } A } +printf"%d\n", Dp[l1][l2]); the } - $ return 0; the}
"Hdoj" 1243 anti-terrorist training camp