hdu 1243 反恐训练营 lcs

来源:互联网 发布:域名叫什么好 编辑:程序博客网 时间:2024/04/28 18:03
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define inf 0x3f3f3f3f#define LL long longusing namespace std;/************************************************designer:hltime:2016/11/15Exe.Time:780 msExe.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;}

0 0
原创粉丝点击