Cod sursa(job #73203)

Utilizator taloibogdanTaloi Bogdan Cristian taloibogdan Data 17 iulie 2007 13:13:43
Problema Dezastru Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.86 kb
Program dezastru;
Var f:text;
    i,k,n,m,p:longint;
    s,pp:real;
    x:array[1..8000] of byte;
    a:array[1..8000] of real;
function cond(k:longint):boolean;
begin
 cond:=true;
 for i:=1 to k-1 do if x[i]=x[k] then cond:=false;
end;
Begin
  assign(f,'dezastru.in');
  reset(f);
  readln(f,n,m);
  for i:=1 to n do
     read(f,a[i]);
  close(f);
  k:=1;
  x[k]:=0;
  s:=0.0;
  while k>0 do
       begin
        p:=0;
        while (x[k]<n) and (p=0) do
             begin
              x[k]:=x[k]+1;
              if cond(k) then p:=1;
             end;
        pp:=1.0;
        if p=0 then k:=k-1
               else if k=m then begin for i:=1 to m do pp:=pp*a[x[i]]; s:=s+pp/(n*(n-1)); end
                           else begin k:=k+1; x[k]:=0; end;
       end;
  assign(f,'dezastru.out');
  rewrite(f);
  Writeln(f,s:0:6);
  close(f);
End.