题目链接:

  http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1030

题目大意

  给定两个字符串的长度和内容,求最长公共子序列。

题目思路:

  【动态规划】

  求最长公共子序列。f[i][j]表示第一个串匹配到i,第二个串匹配到j的最长长度。

 //
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps (1e-8)
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 1004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
char a[N],b[N];
int f[N][N];
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,l;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n))
{
scanf("%d",&m);
scanf("%s%s",a+,b+);
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
f[i][j]=max(f[i-][j],f[i][j-]);
if(a[i]==b[j])f[i][j]=max(f[i][j],f[i-][j-]+);
}
}
printf("%d\n",f[n][m]);
}
return ;
}
/*
// //
*/

千万不要点

【动态规划】XMU 1030 苦恼的月下老人的更多相关文章

  1. 【动态规划】POJ 1161 & ZOJ1463 & XMU 1033 Brackets sequence

    题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1033 http://poj.org/problem?id=1141 ZOJ目前挂了. ...

  2. 【最长下降子序列】【动态规划】【二分】XMU 1041 Sequence

    题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1041 题目大意: 一个二维平面,上面n(n<=1 000 000)个点.问至少选 ...

  3. 【动态规划】XMU 1032 装配线问题

    题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1032 题目大意: 一个物品在2条生产线上加工,每条线上n(n<=1000)个节点 ...

  4. 【动态规划】HDU 1081 & XMU 1031 To the Max

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1081 http://acm.xmu.edu.cn/JudgeOnline/problem.php?i ...

  5. 【动态规划】XMU 1029 矩阵链乘法

    题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1029 题目大意: 题同乘法难题.给n+1个数,头尾不能动,中间的数可取出,取出时代价是 ...

  6. 【动态规划】XMU 1028 Game Boy Advance

    题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1028 题目大意: 求01背包最优解的方案.物件数和物件编号. 题目思路: [动态规划] ...

  7. 【动态规划】XMU 1583 Sequence

    题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1583 题目大意: T组数据,对于n(n<=6000)给定序列Xn(Xn<= ...

  8. 【动态规划】XMU 1588 01序列计数

    题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1588 题目大意: 给n1个0和n2个1,连续的0不超过k1个,连续的1不超过k2个.问 ...

  9. 【动态规划】XMU 1560 新ACM规则

    题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1560 题目大意: 给定n(n<=200)个任务及每个任务的耗时,问m(m< ...

随机推荐

  1. Django Errors Archive

    记录使用 Django 开发中遇到的问题,备用 1. 版本要选好,最好安装上 pip,可以省很多麻烦 2. 如果使用 Postgresql,选 8.1 之后的版本,免去 Retruning 之类的错误 ...

  2. jQuery绑定事件的四种基本方式

    Query中提供了四种事件监听方式,分别是bind.live.delegate.on,对应的解除监听的函数分别是unbind.die.undelegate.off. bind(type,[data], ...

  3. Directive Definition Object

    不知道为什么这个我并没有想翻译过来的欲望,或许我并没有都看熟透,不好误人子弟,原版奉上. Here's an example directive declared with a Directive D ...

  4. 使用Cxf发布Webservice服务,如果待发布的接口中有重载方法,怎么处理??

    使用 @WebMethod(operationName="multiParamByName")  重新指定名字. http://bbs.csdn.net/topics/270059 ...

  5. 启动php-fpm时报错

    [root@localhost ~]# /usr/local/php/sbin/php-fpm [06-Aug-2012 19:17:53] ALERT: [pool www] pm.min_spar ...

  6. 安装php时,make步骤报错make: *** [sapi/fpm/php-fpm] Error 1

    安装PHP过程中,make步骤报错:(集中网络上各种解决方法) (1)-liconv -o sapi/fpm/php-fpm /usr/bin/ld: cannot find -liconv coll ...

  7. RSA PKCS1padding 填充模式

    在BouncyCastle实现RSA的PKCS1V1.5模式中,如果是公钥加密信息(forEncryption=true),密钥长度为1024位,那么输出的密文块长度为128个字节,输入的明文块长度为 ...

  8. JS屏蔽右键菜单,复制,粘帖xxxxx........

    //屏蔽右键菜单 document.oncontextmenu = function (event) { if (window.event) { event = window.event; } try ...

  9. thinkphp整合系列之支付宝RSA加密方式

    thinkphp整合系列之支付宝RSA加密方式上篇博客写的是MD5加密方式:thinkphp整合系列之支付宝MD5加密方式扫码支付http://baijunyao.com/article/75 但是呢 ...

  10. 如何把PPT变小|PowerPoint文档减肥的几种方法

    使用powerpoint制作幻灯片的过程中,经常出现过这样的情况,制作幻灯片时,出于内容的需要和美观的需要,添加了许多图片和Excel表或者OLE对象,成倍增大了文档的体积,结果导致: 1.页面编辑人 ...