#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
struct node
{
int lo,v;
}G[150005];
bool cmp(const node &a,const node &b)
{
if(a.v==b.v)
return a.lo<b.lo;
else
return a.v>b.v;
}
char str1[150050],str2[150050];
int main()
{
int n,p;
while(~scanf("%d%d",&n,&p)&&(n+p))
{
scanf("%s",str1);
scanf("%s",str2);
int t=0,res=0;
G[0].lo=0,G[0].v=0;
for(int i=1;i<=n;i++)
{
if(str1[i-1]!=str2[i-1])
t++;
G[i].v=100*t-i*p;
G[i].lo=i;
}
sort(G,G+1+n,cmp);
int lo=G[0].lo;
for(int i=1;i<=n;i++)
{
if(lo<G[i].lo)
res=max(res,G[i].lo-lo);
else
lo=G[i].lo;
}
if(res)
printf("%d\n",res);
else
printf("No solution.\n");
}
}LA 3716
最新推荐文章于 2025-06-30 16:40:59 发布
本文介绍了一种基于字符串匹配的算法,该算法通过比较两个字符串并计算它们之间的差异来确定最佳匹配位置。通过使用特定的评分机制,算法能够找到使得总成本最小的匹配方案。此方法适用于文本处理和生物信息学等领域。

1854

被折叠的 条评论
为什么被折叠?



