【HDOJ】1243 反恐训练营

LCS.

 /* 1243 */
#include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 2025
#define MAXM 256 char type[MAXM];
int point[MAXM]; char bullet[MAXN];
char kbfz[MAXN];
int dp[MAXN][MAXN];
int n; int min(int a, int b) {
return a<b ? a:b;
} int max(int a, int b) {
return a>b ? a:b;
} int abs(int x) {
return x< ? -x:x;
} int main() {
int i, j, k;
int l1, l2; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%d", &n) != EOF) {
memset(point, , sizeof(point));
scanf("%s", type);
for (i=; i<n; ++i) {
scanf("%d", &k);
point[type[i]] = k;
}
scanf("%s", bullet+);
scanf("%s", kbfz+);
l1 = strlen(bullet+);
l2 = strlen(kbfz+);
for (i=; i<=max(l1, l2); ++i) {
dp[][i] = ;
dp[i][] = ;
}
for (i=; i<=l1; ++i) {
for (j=; j<=l2; ++j) {
if (bullet[i] == kbfz[j]) {
dp[i][j] = dp[i-][j-] + point[bullet[i]];
} else {
k = max(dp[i-][j], dp[i][j-]);
dp[i][j] = max(k, dp[i-][j-]);
}
}
}
printf("%d\n", dp[l1][l2]);
} return ;
}
上一篇:HashMap的笔记


下一篇:【转载】PHP 开发者该知道的 5 个 Composer 小技巧