If I have the following information
two 12-seat-table
two 11-seat-table
one 10-seat-table
How to show all the probabaility?
12 12 11 11 10
12 11 12 11 10
12 10 11 12 11
...
...
usualy for this kind of problem you should use backtracking.
i dind'n quite undesrstand the problem but if you explain it to me i could show you how the program would look like
{ ------------------------------------------------------------ }
function AnsIsLegal(S:string):boolean;
var
aCOunt,
bCOunt,
cCOunt:integer;
i:integer;
begin
aCount := 0;
bCount := 0;
cCount := 0;
for i := 1 to 5 do
begin
case S of
'A': inc(aCOunt);
'B': inc(bCOunt);
'C': inc(cCOunt);
end;
end;
result := true;
if aCOunt <> 2 then
result := false;
if bCOunt <> 2 then
result := false;
if cCOunt <> 1 then
result := false;
end;
{ ------------------------------------------------------------ }
procedure AddToLIst(S:string);
var
i:integer;
begin
if AnsIsLegal(S) then
begin
for i := 1 to 5 do
case S of
'A': write('12 ');
'B': write('11 ');
'C': write('10 ');
end; { case }
writeln('');
inc(Permutations);
end;
end;
{ ------------------------------------------------------------ }
procedure FindAll;
var
Ac,Bc,Cc,Dc,Ec:Char;
S:string;
begin
Permutations := 0;
For Ac := 'A' to 'C' do
For Bc := 'A' to 'C' do
For Cc := 'A' to 'C' do
For Dc := 'A' to 'C' do
For Ec := 'A' to 'C' do
begin
S := Ac + Bc + Cc + Dc + Ec;
AddToList(S);
end;
writeln(Permutations,' Permutations found');
writeln('press return to exit');
readln(S); // in case running in dos window then keep window open
end;
{ ------------------------------------------------------------ }
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.