Cod sursa(job #640444)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 25 noiembrie 2011 19:21:31
Problema Dezastru Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.67 kb
Program dezastru;
 var a:array [0..26,0..26] of double;
     b:array [0..26] of double;
     n,k,i,j:byte;
     fi,fo:text;
function comb(n,k:byte):double;
begin
comb:=1;
 for i:=1 to n do begin
                   comb:=comb*i;
                   if i<=n-k then comb:=comb/i;
                    if i<=k then comb:=comb/i;
                   end;
end;
begin
 assign(fi,'dezastru.in');
  assign(fo,'dezastru.out');
 reset(fi); rewrite(fo);
 readln(fi,n,k);
  for i:=1 to n do begin read(fi,b[i]); a[i,0]:=1; end;
   a[0,0]:=1;
  for i:=1 to k do
   for j:=i to n do
    a[j,i]:=a[j-1,i]+a[j-1,i-1]*b[j];
    write(fo,a[n,k]/comb(n,k):0:6);
 close(fo);
end.