hdu 1243 反恐训练营 最长公共字序列
此题的题意很明确,就是求最长公共子序列;
#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 反恐训练营 最长公共字序列的更多相关文章
- HDU 1243 反恐训练营(最长公共序列)
反恐训练营 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
- HDU 1243 反恐训练营 (动态规划求最长公共子序列)
反恐训练营 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- HDU - 1243 - 反恐训练营
先上题目: 反恐训练营 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 1243 反恐训练营(dp 最大公共子序列变形)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1243 d[i][j] 代表第i 个字符与第 j 个字符的最大的得分.,, 最大公共子序列变形 #inclu ...
- 最长公共字序列.cpp
<span style="color:#993399;">/* By yuan 2014/6/21 At nwpu.xf 1041.最长公共子序列 时限:1000ms ...
- 【HDOJ】1243 反恐训练营
LCS. /* 1243 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MA ...
- HDU1243:反恐训练营
题目链接:反恐训练营 题意:本质上是求最大公共子序列,然后加上一个权值 分析:见代码 //公共子序列问题 //dp[i][j]表示前s1的前i个与s的前j个匹配得到的最大公共子序列 #include& ...
- 反恐训练营(LCS)
反恐训练营 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 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, ...
随机推荐
- baseDao 使用spring3+hibernate4方式
启动异常: java.lang.ClassCastException: org.springframework.orm.hibernate4.SessionHolder cannot be cast ...
- cocos2d-x 用浏览器打开网页
转自:http://www.xuebuyuan.com/1396292.html,http://www.cocoachina.com/bbs/read.php?tid=88589 First!! 源代 ...
- IDA Script: Remove empty auto labels
http://simeonpilgrim.com/blog/2010/03/25/ida-script-remove-empty-auto-labels/ #include <idc.idc&g ...
- Car immobilizer hacking
Karsten Nohl <nohl@srlabs.de>
- Delphi / C++ Builder 使用 UDT ( UDP-based Data Transfer ) 4.11
添加 src/*.cpp 到工程, 修改 Directories and Conditionals, 添加 WIN32 UDT_EXPORTS udt.h 需要 #pragma link " ...
- cocos2d jsb 打包 Android APK
1.首先要会普通的cpp 打包成Android APK 下面所说的是在cocos2d-x 2.2.2 或者 2.3 版本号中.本文在Eclipse总用ndk编译cocos2d-x. 老生常谈cocos ...
- Codeforces Round #312 (Div. 2) A. Lala Land and Apple Trees 暴力
A. Lala Land and Apple Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/cont ...
- C#的WinForm中制作饼状图和柱状图
using System; using System.IO;//用于文件存取 using System.Data;//用于数据访问 using System.Drawing;//提供画GDI+图形的基 ...
- 查询(c语言实现)
/* * Describe:这是一个简单的查询程序 * Date: 2013/12/7 */ #include <stdio.h> #include <stdlib.h> #d ...
- 0c-40-ARC下多对象内存管理
1个人拥有1条狗. 问题1:人拥有狗作为成员变量,此时使用weak,释放过程是什么样? Person *p = [Person new]; Dog *d = [Dog new]; //设置人拥有dog ...