#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define inf 0x3f3f3f3f
#define LL long long
using namespace std;
/************************************************
designer:hl
time:2016/11/15
Exe.Time:780 ms
Exe.Memory:18820 KB
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1243
题意:亲切中文题
题解:LCS裸
todo:其实可以加个优化在上面 就是先把无关的子弹都排除掉。这样可以减少循环的次数
************************************************/
int dp[2100][2100];
int main() {
int i, j, k, l, m, n;
int score[1200];
char type[2100], terror[2100], bullet[2100];
while (~scanf("%d\n", &n)) {
memset(dp, 0, sizeof(dp));
memset(score, 0, sizeof(score));
scanf("%s", type);
for (i = 0; i < n; i++) {
scanf("%d", &score[type[i]]);
}
scanf("%*c");
scanf("%s", bullet);
scanf("%s", terror);
int bulletLen = strlen(bullet);
int terrorLen = strlen(terror);
for (i = 1; i <= bulletLen; i++) {
for (j = 1; j <= terrorLen; j++) {
if (bullet[i - 1] == terror[j - 1]) {
dp[i][j] = max(dp[i - 1][j - 1] + score[terror[j - 1]], dp[i][j]);
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
printf("%d\n", dp[bulletLen][terrorLen]);
}
return 0;
}
hdu 1243 反恐训练营 lcs
最新推荐文章于 2019-04-14 18:30:43 发布