题目大意
略
初步想法
看到$n$的范围才300,直接上暴力。
枚举A、B串开始位置,然后向后扫描,扫$k$个不同的时候停止,更新答案。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<queue> using namespace std; inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj; } int n,k,ans=0; string s1,s2; int main() { ios::sync_with_stdio(false); cin>>n>>k>>s1>>s2; s1=' '+s1; s2=' '+s2; for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) { int pos1=i,pos2=j,cnt=s1[i]!=s2[j]; while(pos1<=n&&pos2<=n&&cnt<=k) { pos1++; pos2++; if(s1[pos1]!=s2[pos2])cnt++; } ans=max(ans,pos1-i); } printf("%d\n",ans); return 0; }
|