记录编号 |
4959 |
评测结果 |
AAAAAAAAAA |
题目名称 |
乘法问题 |
最终得分 |
100 |
用户昵称 |
王瑞祥K |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.038 s |
提交时间 |
2008-10-23 23:15:13 |
内存使用 |
0.29 MiB |
显示代码纯文本
program chf(input,output);
type
shu=array[0..50]of integer;
var
sum,data:array[1..30,1..30]of shu;
n,m:integer;
procedure ini;
var i,j,l,c,code,k:integer;zh,st:string;
begin
assign(input,'chf.in');assign(output,'chf.out');
reset(input);rewrite(output);
readln(n,m);read(st);
for i:=1 to n do
for j:=1 to n-i+1 do begin
zh:=copy(st,i,j); l:=length(zh); c:=0; sum[i,i+j-1][0]:=l;
for k:=l downto 1 do begin inc(c); val(zh[k],sum[i,i+j-1][c],code);end;
end;
end;
procedure mul(a,b:shu;var c:shu);
var i,j:integer;
begin
for i:=1 to a[0] do
for j:=1 to b[0] do begin
c[i+j-1]:=c[i+j-1]+a[i]*b[j];
c[i+j]:=c[i+j-1]div 10+c[i+j];
c[i+j-1]:=c[i+j-1]mod 10;
end;
i:=50;
while (i>=1) and(c[i]=0)do dec(i);
if i=0 then c[0]:=1 else c[0]:=i;
end;
procedure main;
var i,j,k,s:integer;jieguo,max:shu;
begin
for k:=1 to m+1 do
for i:=1 to n do begin
if k=1 then begin for j:=1 to sum[1,i][0] do data[i,1][j]:=sum[1,i][j];
data[i,1][0]:=sum[1,i][0];end
else begin
fillchar(max,sizeof(max),0);
for j:=1 to i-1 do begin
fillchar(jieguo,sizeof(jieguo),0);
mul(data[j,k-1],sum[j+1,i],jieguo);
if jieguo[0]>max[0] then begin
for s:=1 to jieguo[0] do max[s]:=jieguo[s];
max[0]:=s;
end
else
if jieguo[0]=max[0] then begin
s:=jieguo[0];
while (jieguo[s]=max[s])and(s>=1)do dec(s);
if (s<>0)and(jieguo[s]>max[s])then begin
for s:=1 to jieguo[0]do max[s]:=jieguo[s];
max[0]:=s;
end;
end;
end;
for j:=1 to max[0] do data[i,k][j]:=max[j];
data[i,k][0]:=j;
end;
end;
for i:=data[n,m+1][0]downto 1 do write(data[n,m+1][i]);
close(input);close(output);
end;
begin
ini;
main;
end.