Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- fi = 'uva103.inp';
- fo = 'uva103.out';
- type
- box = array[1..10] of longint;
- boxes = array[1..300] of box;
- var
- f,g:text;
- a:boxes;
- fx,fa:array[1..300] of longint;
- n,k,i,j:longint;
- procedure sort(var a:box; k:longint);
- var
- i,j,tmp:longint;
- begin
- for i:=1 to k-1 do
- for j:=i+1 to k do
- if a[i]>a[j] then
- begin
- tmp:=a[i];
- a[i]:=a[j];
- a[j]:=tmp;
- end;
- end;
- procedure swap(var x,y:box);
- var t:box;
- begin
- t:=x; x:=y; y:=t;
- end;
- function cmp(x,y:box):boolean;
- var i:longint;
- begin
- for i:=1 to n do
- if x[i] > y[i] then exit(false);
- exit(true);
- end;
- procedure sort2(var a:boxes; k:longint);
- var
- i,j:longint;
- begin
- for i:=1 to k-1 do
- for j:=i+1 to k do
- if cmp(a[j],a[i]) then swap(a[i],a[j]);
- end;
- procedure dynprog;
- var
- i,j,max:longint;
- begin
- sort2(a,k);
- fillchar(fx,sizeof(fx),0);
- fx[1]:=1;
- max:=0;
- for i:=2 to k do
- begin
- for j:=1 to i-1 do
- if (cmp(a[j],a[i])) and (fx[i] < fx[j]+1) then
- begin
- fx[i]:=fx[j]+1;
- fa[j]:=i;
- end;
- if max<fx[i] then max:=fx[i];
- end;
- writeln(g,max);
- end;
- begin
- assign(f,fi); reset(f);
- assign(g,fo); rewrite(g);
- while not seekeof(f) do
- begin
- readln(f,k,n);
- for i:=1 to k do
- begin
- for j:=1 to n do read(f,a[i,j]);
- sort(a[i],n);
- readln(f);
- end;
- dynprog;
- end;
- close(f); close(g);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement