比赛 10101115 评测结果 AAAEEEEEEE
题目名称 矩形分割 最终得分 30
用户昵称 nick09 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 09:24:19
显示代码纯文本
var
 head,tail,tot,i,j,k,n,m,min:longint;
 dn,dm:array[1..300]of longint;
 a,pn,pm:array[0..1000000]of int64;

procedure go;
var i,j:longint;
begin

  if pn[head]+2<=n then begin
    inc(tail);pn[tail]:=pn[head]+1;pm[tail]:=pm[head];
    a[tail]:=a[head]+dn[pn[tail]]*(pm[tail]+1); end;
  if pm[head]+2<=m then begin
    inc(tail);pm[tail]:=pm[head]+1;pn[tail]:=pn[head];
    a[tail]:=a[head]+dm[pm[tail]]*(pn[tail]+1); end;
  inc(head);
  if (pn[tail]+1=n)and(pm[tail]+1=m)and(a[tail]<min) then min:=a[tail];
end;

Begin
assign(input,'cut.in');reset(input);
assign(output,'cut.out');rewrite(output);
readln(n,m);
for i:=1 to n-1 do read(dn[i]);
for i:=1 to m-1 do read(dm[i]);
if n=2 then if dn[1]<dn[2] then begin k:=dn[1];dn[1]:=dn[2];dn[2]:=k;  end;
if n>2 then
  for i:=1 to n-2 do
    for j:=i+1 to n-1 do
     if dn[i]<dn[j] then begin k:=dn[i];dn[i]:=dn[j];dn[j]:=k;end;
if m=2 then if dm[1]<dm[2]    then begin k:=dm[1];dm[1]:=dm[2];dm[2]:=k;end;
if m>2 then
 for i:=1 to m-2 do
  for j:=i+1 to m-1 do
    if dm[i]<dm[j] then begin k:=dm[i];dm[i]:=dm[j];dm[j]:=k ; end;

tot:=0;head:=0;tail:=0;min:=maxlongint;pn[0]:=0;pm[0]:=0;
fillchar(a,sizeof(a),0);
repeat

go;

until head>tail;

writeln(min);
end.