此题的题意很明确,就是求最长公共子序列;

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int dp[][];
int hash[];
int main()
{
char str[],ter[],fir[];
int n,i,j;
while(scanf("%d",&n)!=EOF)
{
memset(hash,,sizeof(hash));
scanf("%s",&str);
int x;
for(i=;i<n;i++)
{
scanf("%d",&x);
hash[str[i]]=x;
}
scanf("%s%s",&ter,&fir);
int l1,l2;
l1=strlen(ter);
l2=strlen(fir);
int cir=max(l1,l2);
for(i=;i<=cir;i++)
{
dp[][i]=;
dp[i][]=;
}
for(i=;i<=l1;i++)
{
for(j=;j<=l2;j++)
{
if(ter[i-]==fir[j-])
{
dp[i][j]=dp[i-][j-]+hash[ter[i-]];
}
else
dp[i][j]=max(dp[i][j-],dp[i-][j]);
}
}
int Max=;
Max=dp[l1][l2];
printf("%d\n",Max);
}
return ;
}

hdu 1243 反恐训练营 最长公共字序列的更多相关文章

  1. HDU 1243 反恐训练营(最长公共序列)

    反恐训练营 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  2. HDU 1243 反恐训练营 (动态规划求最长公共子序列)

    反恐训练营 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  3. HDU - 1243 - 反恐训练营

    先上题目: 反恐训练营 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. hdu 1243 反恐训练营(dp 最大公共子序列变形)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1243 d[i][j] 代表第i 个字符与第 j 个字符的最大的得分.,, 最大公共子序列变形 #inclu ...

  5. 最长公共字序列.cpp

    <span style="color:#993399;">/* By yuan 2014/6/21 At nwpu.xf 1041.最长公共子序列 时限:1000ms ...

  6. 【HDOJ】1243 反恐训练营

    LCS. /* 1243 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MA ...

  7. HDU1243:反恐训练营

    题目链接:反恐训练营 题意:本质上是求最大公共子序列,然后加上一个权值 分析:见代码 //公共子序列问题 //dp[i][j]表示前s1的前i个与s的前j个匹配得到的最大公共子序列 #include& ...

  8. 反恐训练营(LCS)

    反恐训练营 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  9. URAL 1517 Freedom of Choice(后缀数组,最长公共字串)

    题目 输出最长公共字串 #define maxn 200010 int wa[maxn],wb[maxn],wv[maxn],ws[maxn]; int cmp(int *r,int a,int b, ...

随机推荐

  1. Proxy代理(AOP实现原理)

    AOP基于动态代理实现:返回代理对象 java.lang.reflect 包Proxy 类,构造代理类.newProxyInstance() 就是创建代理对象的方法. Proxy.newProxyIn ...

  2. C# 支付宝接口

    生成URL链接   1using System;  2using System.Data;  3using System.Configuration;  4using System.Collectio ...

  3. Ubuntu12.10 下搭建基于KVM-QEMU的虚拟机环境(十六)

    今天我们继续实验Bridge方式的网络配置. Bridge的逻辑原理图如下: 上图中的“br0”就充当了一个桥的作用,主机上的物理网口eth0等根据需要加入到这个桥里面,所有虚拟机要跟外界通信都通过这 ...

  4. c++ 中文字符串处理方法

    转自:http://hi.baidu.com/hehehehello/item/dcc44a4a6afc690e6dc2f08b C++处理中文的问题困扰我很久了.之前一旦遇到中文基本就投诸java怀 ...

  5. UDT: Breaking the Data Transfer Bottleneck

    http://udt.sourceforge.net/ DT is a reliable UDP based application level data transport protocol for ...

  6. IAR USING PRE- AND POST-BUILD ACTIONS

    Using pre-build actions for time stamping If necessary, you can specify pre-build and post-build act ...

  7. 新建VM_Script

    在Hyper-V群集中,不需要设置VM的自启动,当宿主机意外关机重新启动后,上面的VM会自动转移到另一台主机:如果另一台主机处于关机状态,则宿主机重新启动后,其VM也会自启动(如果其VM在宿主机关机前 ...

  8. C#程序通过模板自动创建Word文档

    引言:前段时间有项目要用c#生成Word格式的计算报告,通过网络查找到很多内容,但是都很凌乱,于是自己决定将具体的步骤总结整理出来,以便于更好的交流和以后相似问题可以迅速的解决! 现通过具体的示例演示 ...

  9. 安装luinxWEB

    Webmin的安装很简单,下面就详细说一下安装步骤. 1.用ssh客户端软件登陆服务器2.切换目录到root下,命令是:cd /root/3.下载Webmin的安装文件,命令是:wget http:/ ...

  10. Category目录

    Category目录 目录 概述——对Category的理解 创建Category Category的用途 概述——对Category的理解 当我们想往原有的类中添加新的成员方法但又不想改变原有的类和 ...