题意
根据字串的 Levenshtein 距离,输出 的对应提示词。
思路
RE 50pts:直接 dp
AC100pts:注意到 的输出一样,则只考虑 dp 中 的情况。
复杂度 。
代码
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
typedef unsigned long long ull;
typedef long long ll;
const ull N=100010,M=100010;
char p[N],s[M];
ull dis()
{
ull n=strlen(p+1),m=strlen(s+1);
if(!n||!m) return n+m;
if(n>=4+m||n+4<=m) return 4;
static ull _f[N][13];
auto f=[&](ull i,ull j)->ull&{ return _f[i][i+5-j]; };
memset(_f,0,sizeof(_f));
for(ull i(0);i<=5;++i) f(i,0)=i;
for(ull j(0);j<=5;++j) f(0,j)=j;
for(ull i(1);i<=n;++i)
{
for(ull j(i<=5?1:i-5);j<=m&&j<=i+5;++j)
{
if(p[i]==s[j]) f(i,j)=std::min({f(i-1,j)+1,f(i,j-1)+1,f(i-1,j-1)});
else f(i,j)=std::min({f(i-1,j),f(i,j-1),f(i-1,j-1)})+1;
}
}
return f(n,m);
}
ull T;
int main()
{
scanf("%llu",&T);
while(T--)
{
scanf("%s%s",p+1,s+1);
ull d=dis();
if(d==0) puts("You're logged in!");
if(d==1) puts("You almost got it. You're wrong in just one spot.");
if(d==2) puts("You almost got it, but you're wrong in two spots.");
if(d==3) puts("You're wrong in three spots.");
if(d>3) puts("What you entered is too different from the real password.");
}
return 0;
}