【NOIP2016练习】T1 string (计数)
2024-09-07 18:45:11
题意:
思路:
const mo=;
var pow,f,exf:array[-..]of int64;
n,k,i:longint;
ans,x,y:int64;
s,t:ansistring; function c(x,y:longint):int64;
begin
exit(f[x]*exf[y] mod mo*exf[x-y] mod mo);
end; function min(x,y:int64):int64;
begin
if x<y then exit(x);
exit(y);
end; begin
assign(input,'1.in'); reset(input);
assign(output,'1.out'); rewrite(output);
readln(n,k);
readln(s);
readln(t);
pow[]:=;
for i:= to n do pow[i]:=pow[i-]* mod mo;
f[]:=;
for i:= to n do f[i]:=f[i-]*i mod mo;
exf[]:=; exf[]:=;
for i:= to n do exf[i]:=exf[mo mod i]*(mo-mo div i) mod mo;
for i:= to n do exf[i]:=exf[i-]*exf[i] mod mo;
ans:=;
for i:= to n do
begin
x:=ord(t[i])-ord('a'); y:=ord(s[i])-ord('a');
ans:=(ans+min(x,y)*c(n-i,k-) mod mo*pow[k-] mod mo) mod mo;
if s[i]<t[i] then
begin
ans:=(ans+c(n-i,k)*pow[k] mod mo) mod mo;
ans:=(ans+(x-y-)*c(n-i,k-) mod mo*pow[k-] mod mo) mod mo;
end;
if s[i]<>t[i] then dec(k);
end;
writeln(ans);
close(input);
close(output);
end.
最新文章
- Docker学习笔记第一章:补充
- JAVA获取CLASSPATH路径
- [转]Hibernate与Jpa的关系,终于弄懂
- JVM调优-Java中的对象
- STM32普通定时器实现延时函数
- js事件3
- 改进RazorPad
- drupal错误: Maximum execution time of 240 seconds exceeded
- swift学习 - tableView自适应高度2(SnapKit Layout)
- .NET 实现Base-64加密解密处理
- Ubuntu配置Django+ Apache2+ mysql
- python中的进程池
- Nginx负载均衡和反向代理的配置和优化
- Confluence 6 外部小工具在其他应用中设置可信关系
- 通过使用浏览器对象模型,输出当前浏览器窗口中打开的文档的URL信息,并将显示在窗口中。
- 超强、超详细Redis入门教程【转】
- 利用Docker搭建java项目开发环境
- python面试题(转)
- oracle 中的exists 和 in 效率问题
- JZYZOJ1539[haoi2015]T2 树链剖分