Description

Takahashi has decided to give a string to his mother.

The value of a string T is the length of the longest common subsequence of T and T', where T' is the string obtained by reversing T. That is, the value is the longest length of the following two strings that are equal: a subsequence of T (possibly non-contiguous), and a subsequence of T' (possibly non-contiguous).

Takahashi has a string S. He wants to give her mother a string of the highest possible value, so he would like to change at most K characters in S to any other characters in order to obtain a string of the highest possible value. Find the highest possible value achievable.

题目大意:在改变原串最多K个字母的前提下,使得T和T的反串的LCS尽量长

Solution

猜个结论:T与T的反串的LCS等于T的最长回文子序列的长度

那么就做完了,做一个区间DP: 设 \(f[i][j][k]\) 表示区间 \([i,j]\) 修改了 \(k\) 次的最长的回文子序列的长度

分修改和不修改两种转移即可

#include<bits/stdc++.h>
using namespace std;
const int N=305;
int f[N][N][N],n,K;char s[N];
int main(){
freopen("pp.in","r",stdin);
freopen("pp.out","w",stdout);
scanf("%s%d",s+1,&K);n=strlen(s+1);
for(int i=1;i<=n;i++)
for(int k=0;k<=K;k++)f[i][i][k]=1;
for(int len=2;len<=n;len++){
for(int i=1;i+len-1<=n;i++){
int j=i+len-1;
for(int k=0;k<=K;k++){
f[i][j][k]=max(f[i+1][j][k],f[i][j-1][k]);
if(s[i]==s[j])f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k]+2);
if(k)f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k-1]+2);
}
}
}
cout<<f[1][n][K]<<endl;
return 0;
}

AtCoder Grand Contest 021 D - Reversed LCS的更多相关文章

  1. AtCoder Grand Contest 021

    A - Digit Sum 2 Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Find t ...

  2. AtCoder Grand Contest 021完整题解

    提示:如果公式挂了请多刷新几次,MathJex的公式渲染速度并不是那么理想. 总的来说,还是自己太弱了啊.只做了T1,还WA了两发.今天还有一场CodeForces,晚上0点qwq... 题解还是要好 ...

  3. Atcoder Grand Contest 021 F - Trinity(dp+NTT)

    Atcoder 题面传送门 & 洛谷题面传送门 首先我们考虑设 \(dp_{i,j}\) 表示对于一个 \(i\times j\) 的网格,其每行都至少有一个黑格的合法的三元组 \((A,B, ...

  4. AtCoder Grand Contest 021题解

    传送门 \(A\) 咕咕 ll n,res;bool fl; int main(){ scanf("%lld",&n),fl=1; while(n>9)res+=9, ...

  5. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  6. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  7. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  8. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  9. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

随机推荐

  1. JAVA中GridBagLayout布局管理器应用详解

    很多情况下,我们已经不需要通过编写代码来实现一个应用程序的图形界面,而是通过强大的IDE工具通过拖拽辅以简单的事件处理代码即可很轻松的完成.但是我们不得不面对这样操作存在的一些问题,有时候我们希望能够 ...

  2. Struts2之配置文件中Action的详细配置(续)

    承接上一篇 4.处理结果的配置 Action类的实例对象调用某个方法,处理完用户请求之后,将返回一个逻辑视图名的字符串.核心Filter收到返回的逻辑视图名字符串,根据struts.xml中的逻辑视图 ...

  3. .Net Core MongoDB 简单操作。

    一:MongoDB 简单操作类.这里引用了MongoDB.Driver. using MongoDB.Bson; using MongoDB.Driver; using System; using S ...

  4. 【深度学习】深入理解ReLU(Rectifie Linear Units)激活函数

    论文参考:Deep Sparse Rectifier Neural Networks (很有趣的一篇paper) Part 0:传统激活函数.脑神经元激活频率研究.稀疏激活性 0.1  一般激活函数有 ...

  5. java基础复习(1)

    用记事本写java文件 打开记事本,编写java文件,需要注意文件名与类名要相同 注意文件的后缀名(也叫拓展名)改为.java java对大小写是敏感的 public class nihao{\ pu ...

  6. 新概念英语(1-129)Seventy miles an hour

    Lesson 129 Seventy miles an hour 时速70英里 Listen to the tape then answer this question. What does Ann ...

  7. 新概念英语(1-93)Our new neighbour

    Lesson 93 Our new neighbour 我们的新邻居 Listen to the tape then answer this question. Why is Nigel a luck ...

  8. 新概念英语(1-15)Your passports please

    Is there a problem wtih the Customers officer? A:Are you Swedish? B:No. We are not. We are Danish. A ...

  9. less规范

    Less 编码规范 (1.1) 简介 该文档主要的设计目标是提高 Less 文档的团队一致性与可维护性. Less 代码的基本规范和原则与 CSS 编码规范 保持一致. 编撰 吕俊涛 本文档由商业运营 ...

  10. python多进程--------linux系统中python的os.fork()方法

    linux下python 创建子进程的原理: os.fork()方法 的原理 为了实现并发.多任务,我们可以在主程序种开启一个进程或者线程.在类unix操作系统当中(非windows),可以用pyth ...