#include <bits/stdc++.h>
using namespace std;
int main()
{
int i,j,dp[][],t;
char a[],b[];
bool now,pre;
scanf("%d",&t);
while(t--)
{
scanf("%s%s",a,b);
memset(dp,,sizeof(dp));
int lena=strlen(a),lenb=strlen(b);
for(now=,pre=,i=; i<lena; i++)
for(swap(now,pre),j=; j<lenb; j++)
if(a[i]==b[j])
dp[now][j+]=dp[pre][j]+;
else
dp[now][j+]=dp[pre][j+]>dp[now][j]?dp[pre][j+]:dp[now][j];
printf("%d\n",dp[now][lenb]);
}
return ;
}

最长公共子序列板/滚动 N^2的更多相关文章

  1. poj1159--Palindrome(dp:最长公共子序列变形 + 滚动数组)

    Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 53414   Accepted: 18449 Desc ...

  2. POJ 1159 Palindrome-最长公共子序列问题+滚动数组(dp数组的重复利用)(结合奇偶性)

    Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...

  3. POJ1159——Palindrome(最长公共子序列+滚动数组)

    Palindrome DescriptionA palindrome is a symmetrical string, that is, a string read identically from ...

  4. POJ 1159 Palindrome(区间DP/最长公共子序列+滚动数组)

    Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 56150   Accepted: 19398 Desc ...

  5. 2021.12.10 P2516 [HAOI2010]最长公共子序列(动态规划+滚动数组)

    2021.12.10 P2516 [HAOI2010]最长公共子序列(动态规划+滚动数组) https://www.luogu.com.cn/problem/P2516 题意: 给定字符串 \(S\) ...

  6. HDU 1513 Palindrome(最长公共子序列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 解题报告:给定一个长度为n的字符串,在这个字符串中插入最少的字符使得这个字符串成为回文串,求这个 ...

  7. [BZOJ2423][HAOI2010]最长公共子序列

    [BZOJ2423][HAOI2010]最长公共子序列 试题描述 字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字符序列X=“x ...

  8. 算法设计 - LCS 最长公共子序列&&最长公共子串 &&LIS 最长递增子序列

    出处 http://segmentfault.com/blog/exploring/ 本章讲解:1. LCS(最长公共子序列)O(n^2)的时间复杂度,O(n^2)的空间复杂度:2. 与之类似但不同的 ...

  9. POJ 1159 Palindrome 最长公共子序列的问题

    Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...

随机推荐

  1. 论文学习 :Learning a Deep Convolutional Network for Image Super-Resolution 2014

    (Learning a Deep Convolutional Network for Image Super-Resolution, ECCV2014) 摘要:我们提出了一种单图像超分辨率的深度学习方 ...

  2. JavaScript 文件拖拽上传插件 dropzone.js 介绍

    http://www.renfei.org/blog/dropzone-js-introduction.html

  3. HyperV - glossary

    Root Partition - sometimes called partition. Manages machine-level functions such as device drivers, ...

  4. log() exp()函数

    1 对数函数表示法 import numpy as np import math print('输出自然底数e:',math.e) # np表示法 # np.log()是以e为底的自然对数 print ...

  5. 中国MOOC_零基础学Java语言_第5周 数组

    第5周 数组 5.1 数组 5.2 数组计算 public class Main { public static void main(String[] args) { for (int i = 1; ...

  6. Elasticsearch入门(二)

    基础概念 Elasticsearch有几个核心概念,从一开始理解这些概念会对整个学习过程有莫大的帮助. 接近实时(NRT) Elasticsearch是一个接近实时的搜索平台.这意味着,从索引一个文档 ...

  7. 关于Unity3D中的SerialField这个Attribute的功能

    首先我们看看效果,以下是源文件的内容: 然后对应的面板: 要注意的地方其实就这里: 可以看出,public默认就可以在面板中进行修改,相应的设为private的isCreateSoldier却不会出现 ...

  8. Discrete Mathematics and Its Applications | 1 CHAPTER The Foundations: Logic and Proofs | 1.4 Predicates and Quantifiers

    The statements that describe valid input are known as preconditions and the conditions that the outp ...

  9. 使用cython库对python代码进行动态编译达到加速效果及python第三方包的制作安装

    1.测试代码:新建  fib.pyx # coding:utf-8 import matplotlib.pyplot as plt import numpy as np from sklearn.cl ...

  10. java中的命名规则

    转载自:http://growstep.diandian.com/post/2011-08-17/3989094 1.类名首字母应该大写.属性(成员变量).方法.对象变量以及所有标识符(如形式参数.实 ...