比赛 |
NOIP_5 |
评测结果 |
AATTT |
题目名称 |
添加号 |
最终得分 |
40 |
用户昵称 |
lc |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-24 21:27:23 |
显示代码纯文本
program day5_2;
type
node=array[0..100] of integer;
var
s:string;
m:integer;
f:array[1..200,0..20] of node;
procedure init;
var
i:integer;
begin
readln(s);
read(m);
end;
function Suan(i,j:integer):node;
var
k:integer;
tm:node;
begin
for k:=j downto i do
tm[j-k+1]:=ord(s[k])-48;
tm[0]:=j-i+1;
Suan:=tm
end;
function plus(a,b:node):node;
var
i:integer;
c:node;
begin
fillchar(c,sizeof(c),0);
if a[0]>b[0] then c[0]:=a[0] else c[0]:=b[0];
for i:=1 to a[0] do
inc(c[i],a[i]);
for i:=1 to b[0] do
inc(c[i],b[i]);
for i:=1 to c[0] do
begin
inc(c[i+1],c[i] div 10);
c[i]:=c[i] mod 10
end;
while c[c[0]+1]>0 do
begin
inc(c[0]);
inc(c[c[0]+1],c[c[0]] div 10);
c[c[0]]:=c[c[0]] mod 10
end;
plus:=c;
end;
function small(a,b:node):boolean;
var
i:integer;
begin
if a[0]<b[0] then exit(true);
if a[0]>b[0] then exit(false);
for i:=a[0] downto 1 do
if a[i]<b[i] then exit(true)
else
if a[i]>b[i] then exit(false);
exit(false);
end;
procedure main;
var
tmp:node;
i,j,k:integer;
begin
for i:=1 to length(s) do
begin
f[i,0,0]:=i;
for k:=i downto 1 do
f[i,0,i-k+1]:=ord(s[k])-48;
end;
for j:=1 to m do
for i:=1 to length(s) do
begin
f[i,j][0]:=maxint;
for k:=j to i-1 do
begin
tmp:=plus(f[k,j-1],Suan(k+1,i));
if small(tmp,f[i,j])
then f[i,j]:=tmp
end;
end;
end;
procedure print;
var
i:integer;
begin
for i:=f[length(s),m][0] downto 1 do
write(f[length(s),m][i]);
writeln;
end;
begin
assign(input,'exam4.in');
assign(output,'exam4.out');
reset(input); rewrite(output);
init;
main;
print;
close(input); close(output);
end.