记录编号 137978 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 神奇的压缩机 最终得分 100
用户昵称 Gravatar稠翼 是否通过 通过
代码语言 Pascal 运行时间 0.394 s
提交时间 2014-11-05 15:40:06 内存使用 0.20 MiB
显示代码纯文本
program cogs1788;
var
   a,b:longint;
   s:ansistring;
   d,x:array[0..5000]of longint;
   tot,i,j,k,n:longint;
procedure init;
begin
     assign(input,'WinCHG.in');reset(input);
     assign(output,'WinCHG.out');rewrite(output);
end;
function min(a,b:longint):longint;
begin
     if a<b then exit(a);
     exit(b);
end;
procedure main;
begin
     readln(s);n:=length(s);
     readln(a,b);
     for i:=1 to n do
     for j:=1 to i-1 do
     begin
          k:=j;tot:=0;
          while(i+tot<=n)and(s[k]=s[i+tot]) do
          begin
               inc(tot);
               inc(k);
               if k>=i then k:=j;
          end;
          if tot>x[i] then x[i]:=tot;
     end;
     for i:=1 to n do
     begin
          if i=1 then d[i]:=a else d[i]:=a+d[i-1];
          for k:=1 to i-1 do
          begin
               if x[k]<i-k+1 then continue;
               if k<>1 then d[i]:=min(d[i],d[k-1]+b)
               else d[i]:=min(d[i],b);
          end;
     end;
     writeln(d[n]);
end;
begin
     init;
     main;
end.