比赛 NOIP_5 评测结果 AWWEE
题目名称 添加号 最终得分 20
用户昵称 elysian 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-09-24 21:42:09
显示代码纯文本
program elysian;
const
fin='exam4.in';fout='exam4.out';
var
f1,f2:text;
s:string;
a:array[1..200] of integer;
he:array[1..200,1..200] of longint;
f:array[0..200,0..20] of longint;
n,m,ad:integer;

procedure init;
var i,j,k,p,wei:longint;
tmp:string;
begin
assign(f1,fin);reset(f1);
readln(f1,s);
read(f1,m);
close(f1);
n:=length(s);
for i:=1 to n do
a[i]:=ord(s[i])-48;

for i:=1 to n do
for j:=i to n do
begin
tmp:=copy(s,i,j-i+1);
wei:=1;
  for p:= length(tmp) downto 1 do
   begin
  he[i,j]:=he[i,j]+(ord(tmp[p])-48)*wei;
  wei:=wei*10;
  end;
end;
end;


procedure dp;
var
i,j,p:longint;
begin
for i:=1 to n do
for j:=1 to n do f[i,j]:=maxlongint;
for i:=1 to n do f[i,1]:=he[1,i];

for j:=2 to m+1 do
for i:=1 to n do
for p:=j-1 to i-1 do
if  f[p,j-1]+he[p+1,i]<f[i,j] then f[i,j]:=f[p,j-1]+he[p+1,i];

end;



begin
init;
dp;
assign(f2,fout);rewrite(f2);
writeln(f2,f[n,m+1]);
close(f2);
end.