记录编号 2056 评测结果 AAAAAAAAAA
题目名称 乘法问题 最终得分 100
用户昵称 Gravatarbing 是否通过 通过
代码语言 Pascal 运行时间 1.027 s
提交时间 2008-09-11 13:42:04 内存使用 0.00 MiB
显示代码纯文本
program bing;
var
 f1,f2,f3:text;
 n,k,l:integer;
 s:string;
 a:array[1..30,1..30,0..30] of string;
procedure init;
begin
 assign(f1,'chf.in');reset(f1);
 assign(f2,'chf.out');rewrite(f2);

 readln(f1,n,k);
 readln(f1,s);
end;
function cheng(x,y:string):string;
var
 aa:array[1..50,1..50] of longint;
 x1,y1,z1:array[1..50] of longint;
 m,n,i,j,k,l1,l2:longint;
begin
 l1:=length(x);l2:=length(y);
 if l1<l2 then m:=l2 else m:=l1;
 for i:=1 to m do begin
  x1[i]:=0;y1[i]:=0;z1[i]:=0;end;
 for i:=l1 downto 1 do x1[l1+1-i]:=ord(x[i])-ord('0');
 for i:=l2 downto 1 do y1[l2+1-i]:=ord(y[i])-ord('0');
 for i:=1 to l2 do
  for j:=1 to l1 do aa[i,j]:=x1[j]*y1[i];
  fillchar(z1,sizeof(z1),0);
 for i:=1 to l2 do
  for j:=1 to l1 do z1[i+j]:=z1[i+j]+aa[i,j];
 for i:=2 to l2+l1 do begin
  z1[i+1]:=z1[i+1]+z1[i] div 10;z1[i]:=z1[i]mod 10;end;
  n:=l1+l2+1;
 if (x='0')or (y='0') then cheng:='0';
 while (z1[n]=0) and (n>1) do n:=n-1;
 cheng:='';
 for i:=n downto 2 do
  cheng:=cheng+chr(z1[i]+48);
 end;
procedure nb;
var
 i,j,l,k1,i1,j1:integer;
 t:string;
 p,q,code:longint;
begin
 for i:=1 to n do
 for j:=1 to n do

 if i+j-1<=n then
  a[i,j,0]:=copy(s,i,j);
 for j:=2 to n do
 for i:=1 to n do  if i+j-1<=n then
 for l:=1 to j-1 do
 begin
  for k1:=0 to l-1 do
  for j1:=1 to j-1 do
  begin
   t:=cheng(a[i,j1,k1],a[i+j1,j-j1,l-k1-1]);
  if length(t)>length(a[i,j,l]) then
   a[i,j,l]:=t
   else
   if (length(t)=length(a[i,j,l]))and (t>=a[i,j,l])  then
  a[i,j,l]:=t;
  end;
 end;
end;


begin
 init;
 nb;
 if a[1,n,k]='' then a[1,n,k]:='0';
 write(f2,a[1,n,k]);
 close(f1);close(f2);
end.