当前位置:网站首页>The exchange - string dp
The exchange - string dp
2022-08-02 11:00:00 【WAWA source】

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define int long long
const int N = 200010;
int n,k;
string s;
vector<int>vec[30];
int f[1010][1010];
int cal(vector<int> vec)
{
int n=vec.size();
memset(f,0,sizeof f);
for(int i=0;i+1<n;i++)
f[i][i+1]=vec[i+1]-vec[i]-1;
for(int i=2;i<n;i++)
{
for(int j=0;j+i<n;j++)
{
int l=j,r=j+i;
f[l][r]=f[l+1][r-1]+abs(vec[r]-vec[l])-(r-l);
}
}
int res=0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(f[i][j]<=k)res=max(j-i+1,res);
return res;
}
signed main()
{
cin>>s>>k;
for(int i=0;i<s.size();i++)
vec[s[i]-'a'].push_back(i);
int res=0;
for(int i=0;i<26;i++)res=max(res,cal(vec[i]));
cout<<res<<'\n';
}
边栏推荐
猜你喜欢
随机推荐
超赞!发现一个APP逆向神器!
mysql清除binlog日志文件
OSI 七层模型和TCP/IP模型及对应协议(详解)
初探zend引擎
太帅了!我用炫酷大屏展示爬虫数据!
3 d laser slam: LeGO - LOAM - ground point extracting method and the analysis of the code
Why use BGP?
Failed to configure mysql, what's going on?
4年手工测试被应届生取代了,用血与泪的教训给xdm一个忠告,该学自动化了...
How to encapsulate the wx.request() request of WeChat applet
[Science of Terminology] For those difficult words about the integrated workbench, read this article to understand in seconds!
Oracle 19c配置ob server
You Only Hypothesize Once: 用旋转等变描述子估计变换做点云配准(已开源)
FinClip | 来了, 2022 年 7 月更新大盘点
阿里CTO程立:阿里巴巴开源的历程、理念和实践
情景剧《重走长征路》上演
从众多接口中脱颖而出的最稳定的接口——淘宝详情api
Mysql环境变量的配置(详细图解)
字节跳动软件测试岗,收到offer后我却拒绝了~给面试的人一些忠告....
X86函数调用模型分析









