思路:

滚动数组;

贴一发挫code…

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
typedef __int64 LL; const int N=5e3+10; int dp[3][N];
int k,n;
char s[N];
char s1[N];
char s2[N]; int main()
{
scanf("%d",&n);
scanf("%s",s+1);
strcpy(s1+1,s+1);
// strrev(s+1); //poj也给CE了...
// strcpy(s2+1,s+1);
for(int i=1;i<=n;i++)
s2[i]=s[n-i+1];
k=1;
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
k=1-k;
for(int j=1;j<=n;j++)
{
if(s1[i]==s2[j])
dp[k][j]=dp[1-k][j-1]+1;
else
dp[k][j]=max(dp[k][j-1],dp[1-k][j]);
}
}
printf("%d\n",n-dp[k][n]);
}

poj1159 【LCS】的更多相关文章

  1. 【线型DP】【LCS】洛谷P4303 [AHOI2006]基因匹配

    P4303 [AHOI2006]基因匹配 标签(空格分隔): 考试题 nt题 LCS优化 [题目] 卡卡昨天晚上做梦梦见他和可可来到了另外一个星球,这个星球上生物的DNA序列由无数种碱基排列而成(地球 ...

  2. POJ 2250 Compromise【LCS】+输出路径

    题目链接:https://vjudge.net/problem/POJ-2250 题目大意:给出n组case,每组case由两部分组成,分别包含若干个单词,都以“#”当结束标志,要求输出最长子序列. ...

  3. poj 1159 Palindrome 【LCS】

    任意门:http://poj.org/problem?id=1159 解题思路: LCS + 滚动数组 AC code: #include <cstdio> #include <io ...

  4. lightoj1010【LCS】

    题意: 求最长公共子序列,并且这个子序列是字典序最小. 思路: LCS附一个值,dp[i][j].first代表以i,j的LCS的长度,dp[i][j].second代表LCS结尾元素,然后利用路径输 ...

  5. hdoj 1159 Common Subsequence【LCS】【DP】

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  6. 【线型DP】【LCS】UVA_10635 Prince and Princess

    嘤嘤嘤,我又来了,刚A完就写,这个沙雕题有丶恶心.                  ???时间4.11发现所有表情包都莫得了 题目: In an n×n chessboard, Prince and ...

  7. poj 1458 Common Subsequence【LCS】

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43132   Accepted: 17 ...

  8. HDU1069_Monkey and Banana【LCS】

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. HDU 1503【LCS】(字符串合并输出)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1503 题目大意: 给两个字符串,组成一个长度尽可能小的字符串,它包含上述两个字符串,且原字符串中的字符 ...

随机推荐

  1. 关于 thinkPHP Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback 关于thinkPHP rpc调 ...

  2. 133. Clone Graph (3 solutions)——无向无环图复制

    Clone Graph Clone an undirected graph. Each node in the graph contains a label and a list of its nei ...

  3. a#x#i#o#s封装

    封装的js文件如下: /* 用于修改 axios 的一些公用配置,具体参看文档 */import axios from 'axios'import store from '@/store/index. ...

  4. Intel Naming Strategy--2

    http://en.wikipedia.org/wiki/Intel_Corporation#Naming_strategy Naming strategy[edit] In 2006, Intel ...

  5. linux 输入子系统(1) -Event types

    输入系统协议用类型types和编码codecs来表示输入设备的值并用此来通知用户空间的应用程序. input协议是一个基于状态的协议,只有当相应事件编码对应的参数值发生变化时才会发送该事件.不过,状态 ...

  6. bash_profile打不开怎么办,用nano .bash_profile打开

    I’ve spent years curating a collection of Mac bash aliases and shortcuts to make my life easier. My ...

  7. MapReduce算法形式一:WordCount

    MapReduce算法形式一:WordCount 这种形式可以做一些网站登陆次数,或者某个电商网站的商品销量啊诸如此类的,主要就是求和,但是求和之前还是要好好清洗数据的,以免数据缺省值太多,影响真实性 ...

  8. 逼近法(例 poj3208、poj1037)

    ​ 逼近法是一种很奇妙的算法,以为"逼近"这一种思想在很多的算法中都有体现.诸如:像我们的二分答案,不断地排除决策集合的一半以接近我们的最终答案:我们的树上倍增求 \(LCA\) ...

  9. About "self"

    Class method can't refer derectly to instance variables. Within the body of  a class method, self re ...

  10. react native 中的ListView

    ListView 的运用: 1.首先在react native中引入这个组件: 2.初始化的ListView 的相关属性: constructor(props) { super(props); con ...