题意:

思路:生成一些回文拼起来使生成的段数最小

显然存在一种最优的方案,使生成的那些回文是目标串的极长回文子串

求出对于每个位置的最长回文子串,问题就转化成了:

给定一些已知起始和终止位置的线段,求覆盖住整个区域的最小线段数量

这个可以BIT做,求当前已经覆盖的区域最远能拓展到哪里

也可以预处理一下前缀最小值,跳转时直接调用即可

 const oo=;
var t,a,x,y,p:array[..]of longint;
len,n,i,id,mx,ans,m:longint;
ch:ansistring; function lowbit(x:longint):longint;
begin
exit(x and (-x));
end; function max(x,y:longint):longint;
begin
if x>y then exit(x);
exit(y);
end; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; procedure update(x,y:longint);
begin
while x<=n- do
begin
t[x]:=max(t[x],y);
x:=x+lowbit(x);
end;
end; function query(x:longint):longint;
begin
query:=-oo;
while x> do
begin
query:=max(query,t[x]);
x:=x-lowbit(x);
end;
end; begin
assign(input,'bzoj3790.in'); reset(input);
assign(output,'bzoj3790.out'); rewrite(output);
while not eof do
begin
readln(ch);
len:=length(ch);
if len= then break;
fillchar(a,sizeof(a),);
fillchar(p,sizeof(p),);
n:=; a[]:=; a[]:=;
for i:= to len do
begin
inc(n); a[n]:=ord(ch[i])-ord('a')+;
inc(n); a[n]:=;
end;
inc(n); a[n]:=;
mx:=; id:=;
for i:= to n- do
begin
if mx>i then p[i]:=min(p[id*-i],mx-i)
else p[i]:=;
while a[i-p[i]]=a[i+p[i]] do inc(p[i]);
if p[i]+i>mx then
begin
mx:=p[i]+i; id:=i;
end;
end;
for i:= to m do
begin
x[i]:=; y[i]:=;
end;
m:=;
for i:= to n- do
begin
inc(m); x[m]:=i-p[i]; y[m]:=i+p[i]-;
end;
fillchar(t,sizeof(t),);
for i:= to m do update(x[i],y[i]);
i:=; ans:=;
while i<n- do
begin
i:=query(i+);
inc(ans);
end;
writeln(ans-);
end;
close(input);
close(output);
end.

最新文章

  1. Guava - EventBus(事件总线)
  2. [CareerCup] 13.4 Depp Copy and Shallow Copy 深拷贝和浅拷贝
  3. Thwarting Buffer Overflow Attacks Stack Randomization
  4. 在腾讯云上创建您的SQL Cluster(3)
  5. 黑马程序员——JAVA基础之抽象和接口 , 模版方法设计模式
  6. TortoiseGit和Git操作git@osc简要说明
  7. 使用jquery插件报错:TypeError:$.browser is undefined的解决方法
  8. 【转】C++ function、bind以及lamda表达式
  9. C# 简单的图像边缘提取
  10. Github 常用命令
  11. xHTML+div布局:三个div,两边div宽度固定,中间div宽度自适应
  12. CSS3 grayscale滤镜图片变黑白实例页面
  13. RVCT的Linux环境变量配置 ARM&#174; RVDS™ 4.1(b713)
  14. Python基础知识学习_Day2
  15. rpm体系下的linux安装httpd+mysql+…
  16. Python 函数返回值
  17. Asp.Net Web API(四)
  18. 使用 phpstudy 搭建本地测试环境
  19. Spring Cloud:多环境配置、eureka 安全认证、容器宿主机IP注册
  20. (15)线程---Condition条件

热门文章

  1. golang——随机数(math/rand包与crypto/rand包)
  2. 公司4:JrVue主题定制-2
  3. 【css】回想下经典的布局
  4. C#上机作业及代码Question2
  5. 上传txt文件编码格式判断(文本乱码解决方法)
  6. java 装饰者类
  7. 从 C++ 到 Objective-C 的快速指南
  8. 微信小程序打卡第五天
  9. js中时钟表盘
  10. JavaScript设计模式 (1) 原型模式