当前位置:网站首页>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';
}
边栏推荐
猜你喜欢
随机推荐
注意力机制
Outsourced Student Management System Architecture Documentation
21天学习挑战赛--第一天打卡(屏幕密度)
Oracle 19c配置ob server
LeetCode每日一练 —— 225. 用队列实现栈
Rear tube implements breadcrumb function
如何封装微信小程序的 wx.request() 请求
You Only Hypothesize Once: 用旋转等变描述子估计变换做点云配准(已开源)
如何选择一块真正“好用的、性能高”的远程控制软件
ansible模块--yum模块
云原生应用平台的核心模块有哪些
开箱即用-使用异步加载布局来优化页面启动速度的几种方案
STM32+MPU6050设计便携式Mini桌面时钟(自动调整时间显示方向)
How to technically ensure the quality of LED display?
博云入选Gartner中国DevOps代表厂商
21 Days Learning Challenge - Day 1 Punch (Screen Density)
STM32+MPU6050 Design Portable Mini Desktop Clock (Automatically Adjust Time Display Direction)
Geoffery Hinton: The Next Big Thing in Deep Learning
Event 对象,你很了解吗?
Multithreading (Basic) - 40,000 word summary









