记录编号 |
138043 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
神奇的压缩机 |
最终得分 |
100 |
用户昵称 |
黑駒 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.546 s |
提交时间 |
2014-11-05 16:37:49 |
内存使用 |
0.20 MiB |
显示代码纯文本
var s,s1:ansistring;
w1,w2,i,j,k,ans,len,tot,now:longint;
l:array[0..5000] of longint;
f:array[0..5000] of longint;
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 init;
begin
readln(s);
read(w1,w2);
fillchar(l,sizeof(l),0);
filldword(f,sizeof(f) div 4,maxlongint);
f[0]:=0;
len:=length(s);
for i:=1 to len do
for j:=1 to i-1 do
begin
tot:=0;
now:=j;
while (s[now]=s[i+tot]) and ((i+tot)<=len) do
begin
inc(now);
inc(tot);
if (now>=i) then now:=j;
end;
l[i]:=max(l[i],tot);
end;
end;
procedure main;
var i,j,k:longint;
begin
for i:=1 to len do
begin
f[i]:=f[i-1]+w1;
for j:=1 to i do
begin
if l[j]<(i-j+1) then continue;
f[i]:=min(f[i],f[j-1]+w2);
end;
end;
writeln(f[len]);
end;
begin
assign(input,'WinCHG.in');
assign(output,'WinCHG.out');
reset(input);
rewrite(output);
init;
{for i:=1 to len do write(l[i],' ');}
main;
close(input);
close(output);
end.