ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1115. Ships

I got TL.Can anybody help me?
Posted by TaoZhang 20 Oct 2002 08:23
const
 inp='';

var
 f:text;
 a:array[1..9,1..99]of 0..1;
 b:array[1..9]of integer;
 c:array[1..99]of integer;
 n,m,l:shortint;

procedure print;
 var
  e,max:shortint;
 begin
  for l:=1 to m do
   begin
    max:=0;
    for e:=1 to n do if a[l,e]=1 then max:=max+1;
    writeln(max);
    for e:=1 to n do if a[l,e]=1 then write(c[e],' ');
    writeln;
   end;
  halt;
 end;

procedure found(i:shortint);
 var
  j:shortint;
 begin
  for j:=1 to m do
   if b[j]-c[i]>=0 then
    begin
     a[j,i]:=1;b[j]:=b[j]-c[i];
     if i<>1 then found(i-1) else print;
     a[j,i]:=0;b[j]:=b[j]+c[i];
    end;
 end;

begin
 fillchar(a,sizeof(a),0);
 assign(f,inp);reset(f);
 readln(f,n,m);
 for l:=1 to n do readln(f,c[l]);
 for l:=1 to m do readln(f,b[l]);
 close(f);
 found(n);
end.