比赛 |
10101115 |
评测结果 |
AAAAAAAAAA |
题目名称 |
矩形分割 |
最终得分 |
100 |
用户昵称 |
mate |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-15 08:23:13 |
显示代码纯文本
- program mwt;
- Type c=array[0..2002] of longint;
- Var n,m,i,j:longint;
- a,b:c;
- f:array[0..2002,0..2002] of longint;
-
- Function min(x,y:longint):longint;
- begin
- if x<y then min:=x
- else min:=y;
- end;
-
- Procedure sort(p,q:longint; var a:c);
- var l,r,o,x:longint;
- begin
- l:=p; r:=q;
- o:=a[l+random(r-l+1)];
- repeat
- while a[l]>o do inc(l);
- while o>a[r] do dec(r);
- if l<=r then begin
- x:=a[l];
- a[l]:=a[r];
- a[r]:=x;
- inc(l); dec(r);
- end;
- until l>r;
- if p<r then sort(p,r,a);
- if l<q then sort(l,q,a);
- 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(a[i]); readln;
- for i:=1 to m-1 do read(b[i]); readln;
- randomize;
- sort(1,n-1,a);
- sort(1,m-1,b);
- for i:=1 to n-1 do f[i,0]:=f[i-1,0]+a[i];
- for i:=1 to m-1 do f[0,i]:=f[0,i-1]+b[i];
- for i:=1 to n-1 do
- for j:=1 to m-1 do
- f[i,j]:=min(f[i-1,j]+a[i]*(j+1),f[i,j-1]+b[j]*(i+1));
- writeln(f[n-1,m-1]);
- End.