记录编号 137995 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 神奇的压缩机 最终得分 100
用户昵称 Gravatar东方老败 是否通过 通过
代码语言 Pascal 运行时间 0.619 s
提交时间 2014-11-05 15:55:41 内存使用 0.20 MiB
显示代码纯文本
var n,i,j,k,a,b,l,o1,o2,o3:longint;
    s:ansistring;
	f:array[0..5013]of longint;
	g:array[0..5013]of longint;
	u,v,t,p,q:ansistring;
    ch:char;

procedure init;
begin
i:=1;
readln(s);l:=length(s);
while s[l]=' ' do
begin
 delete(s,l,1);
 dec(l);
end;
readln(a,b);
end;

function min(x,y:longint):longint;
begin
if x<y then exit(x);exit(y);
end;

function max(x,y:longint):longint;
begin
if x>y then exit(x);exit(y);
end;

procedure deal;//预处理每个位置最多可以复制多长
var tot,k:longint;
begin
for i:=1 to l do
  for j:=1 to i-1 do
  begin
  k:=j;tot:=0;
  while (tot+i<=l)and(s[k]=s[i+tot])do
   begin
   inc(tot);inc(k);
   if k>=i then k:=j;
   end;
  g[i]:=max(g[i],tot);
  end;
end;

procedure work;
begin
deal;
//for i:=1 to l do writeln(g[i]);

fillchar(f,sizeof(f),$7f);
f[0]:=0;
for i:=1 to l do
begin
 f[i]:=f[i-1]+a;
 for j:=1 to i-1 do
 if g[j]+j-1>=i then f[i]:=min(f[i],f[j-1]+b);
 //\writeln(i,' ',f[i],' ',g[i]);
end;
writeln(f[l]);
end;

begin
assign(input,'WinCHG.in');reset(input);
assign(output,'WinCHG.out');rewrite(output);
init;
work;
close(output);
end.