LYDSY模拟赛day1 String Master

LYDSY模拟赛day1 String Master

/*
暴力枚举两个后缀,计算最长能匹配多少前缀。
最优策略一定是贪心改掉前 k 个失配的字符。
时间复杂度 O(n3)。
*/
#include<cstdio>
int n,m,i,j,k,x,y,ans;char a[310],b[310];
int main(){
  freopen("master.in","r",stdin);freopen("master.out","w",stdout);
  scanf("%d%d%s%s",&n,&m,a+1,b+1);
  for(i=1;i<=n;i++)for(j=1;j<=n;j++)
    for(x=i,y=j,k=0;x<=n&&y<=n;x++,y++){
      if(a[x]!=b[y]){
        k++;
        if(k>m)break;
      }
      if(ans<x-i+1)ans=x-i+1;
    }
  printf("%d",ans);
  fclose(stdin);fclose(stdout);
  return 0;
}

 

相关文章:

  • 2021-08-05
  • 2021-05-02
  • 2021-08-25
  • 2022-12-23
  • 2022-02-13
  • 2022-03-04
  • 2021-11-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案