题意:
思路:
1 const mo=1000000007; 2 var pow,f,exf:array[-100001..100001]of int64; 3 n,k,i:longint; 4 ans,x,y:int64; 5 s,t:ansistring; 6 7 function c(x,y:longint):int64; 8 begin 9 exit(f[x]*exf[y] mod mo*exf[x-y] mod mo); 10 end; 11 12 function min(x,y:int64):int64; 13 begin 14 if x<y then exit(x); 15 exit(y); 16 end; 17 18 begin 19 assign(input,'1.in'); reset(input); 20 assign(output,'1.out'); rewrite(output); 21 readln(n,k); 22 readln(s); 23 readln(t); 24 pow[0]:=1; 25 for i:=1 to n do pow[i]:=pow[i-1]*25 mod mo; 26 f[0]:=1; 27 for i:=1 to n do f[i]:=f[i-1]*i mod mo; 28 exf[0]:=1; exf[1]:=1; 29 for i:=2 to n do exf[i]:=exf[mo mod i]*(mo-mo div i) mod mo; 30 for i:=1 to n do exf[i]:=exf[i-1]*exf[i] mod mo; 31 ans:=1; 32 for i:=1 to n do 33 begin 34 x:=ord(t[i])-ord('a'); y:=ord(s[i])-ord('a'); 35 ans:=(ans+min(x,y)*c(n-i,k-1) mod mo*pow[k-1] mod mo) mod mo; 36 if s[i]<t[i] then 37 begin 38 ans:=(ans+c(n-i,k)*pow[k] mod mo) mod mo; 39 ans:=(ans+(x-y-1)*c(n-i,k-1) mod mo*pow[k-1] mod mo) mod mo; 40 end; 41 if s[i]<>t[i] then dec(k); 42 end; 43 writeln(ans); 44 close(input); 45 close(output); 46 end.