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, ...
随机推荐
- Pyqt5.2.1生成的.ui文件转换成.py
cmd C:\>pyuic5 ui文件路径 -o 要生成的py文件路径 如下: C:\>pyuic5 c:\python33\lib\site-packages\pyqt5\uic\log ...
- UI:数据持久化
数据持久化 参考1 参考2 参考3 什么是数据持久化,就是将文件保存在本地的硬盘中,使得应用程序或者机器重启后可以继续访问以前保留的数据.IOS开发中有许多的数据持久化方案. 如下面五种方案 ...
- wchar_t 和 char 之间转换
vc++2005以后,Visual studio 编译器默认的字符集为Unicode.VC中很多字符处理默认为宽字符wchar_t,如CString的getBuffer(),而一些具体操作函数的输入却 ...
- 基于KVM的虚拟化研究及应用
引言 虚拟化技术是IBM在20世纪70年代首先应用在IBM/370大型机上,这项技术极大地提高了大型机资源利用率.随着软硬件技术的迅速发展,这项属于大型机及专利的技术开始在普通X86计算机上应用并成为 ...
- android自定义相册 支持低端机不内存溢出
1 之前在网上看的自定义相册很多时候在低端机都会内存溢出开始上代码把 首先我们要拿到图片的所有路径 cursor = context.getContentResolver().query( Media ...
- PostgreSQL中的AnyArray例子
http://www.joeconway.com/presentations/function_basics.pdf CREATE FUNCTION myappend(anyarray, anyele ...
- 负margin使用权威指南
自CSS2早在1998年,推荐表的使用已经慢慢褪色成背景和历史书中.正因为如此,CSS布局从那时起一直编码优雅的代名词. 的所有CSS概念设计师所使用,奖项可能需要给负margin的使用是最至少谈论的 ...
- 【剑指offer】递归循环两种方式反转链表
转载请注明出处:http://blog.csdn.net/ns_code/article/details/25737023 本文分别用非递归和递归两种方式实现了链表的反转,在九度OJ上AC. 题目描写 ...
- C++ CopyFile
复制文件 关键点 CopyFile The CopyFile function copies an existing file to a new file. The CopyFileEx functi ...
- 【转】android开源项目和框架
特效: http://www.androidviews.net/ http://www.theultimateandroidlibrary.com/ 常用效果: 1. https://github ...