AtCoder Grand Contest 021 D - Reversed LCS
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的更多相关文章
- AtCoder Grand Contest 021
A - Digit Sum 2 Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Find t ...
- AtCoder Grand Contest 021完整题解
提示:如果公式挂了请多刷新几次,MathJex的公式渲染速度并不是那么理想. 总的来说,还是自己太弱了啊.只做了T1,还WA了两发.今天还有一场CodeForces,晚上0点qwq... 题解还是要好 ...
- Atcoder Grand Contest 021 F - Trinity(dp+NTT)
Atcoder 题面传送门 & 洛谷题面传送门 首先我们考虑设 \(dp_{i,j}\) 表示对于一个 \(i\times j\) 的网格,其每行都至少有一个黑格的合法的三元组 \((A,B, ...
- AtCoder Grand Contest 021题解
传送门 \(A\) 咕咕 ll n,res;bool fl; int main(){ scanf("%lld",&n),fl=1; while(n>9)res+=9, ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
随机推荐
- 个人总结——Beta阶段
Beta总结 我们在beta 结束之后, 每位写一个博客, 回顾并总结自己的beta过程,哪些方面做的好的,哪些方面做得不足需要改进的 回答问题 分析在Alpha阶段自己提出的五个问题,针对每个问题, ...
- 400多个开源项目以及43个优秀的Swift开源项目-Swift编程语言资料大合集
Swift 基于C和Objective-C,是供iOS和OS X应用编程的全新语言,更加高效.现代.安全,可以提升应用性能,同时降低开发难度. Swift仍然处于beta测试的阶段,会在iOS 8发布 ...
- Flask-uploads 简单使用
pip install flask-uploads#先导入次此处需要用到的库: from flask_uploads import UploadSet, IMAGES, configure_uploa ...
- java unicode和字符串间的转换
package ykxw.web.jyf; /** * Created by jyf on 2017/5/16. */ public class unicode { public static voi ...
- Linux下关闭Tomcat残留线程
ps -ef | grep tomcat kill -9 {pid}
- vue的简单tab
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" ...
- JAVA_SE基础——34.static修饰成员变量
需求:描述一下学校的学生. 特点:都是中国人.... 测试代码1: class Student{ String name; String country = "中国"; //国籍 ...
- C语言头文件引用
1,引用分为两种 firs:include<fileName.h> 引用系统头文件一般用<>. second:include"fileName.h" 引用自 ...
- istio入门(02)istio的架构和概念
Istio从逻辑上可以分为数据平面和控制平面: 数据平面主要由一系列的智能代理(Envoy)组成,管理微服务之间的网络通信 控制平面负责管理和配置这些智能代理,并动态执行策略 主要由以下组件构成 En ...
- codeforces 798c Mike And Gcd Problem
题意: 给出一个数列,现在有一种操作,可以任何一个a[i],用a[i] – a[i+1]和a[i]+a[i+1]替代a[i]和a[i+1]. 问现在需要最少多少次操作,使得整个数列的gcd大于1. 思 ...