Cod sursa(job #674237)

Utilizator oancea_horatiuOancea Horatiu oancea_horatiu Data 5 februarie 2012 21:01:15
Problema Dezastru Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.81 kb
var p:array[1..26] of real;
    b:array[1..26] of longint;
    pt,pp,a:real;
    n,k,m,i,j,c:longint;
    o,d:text;
function check(ii:longint):boolean;
var i:longint;
  begin
    check:=true;
    for i:=1 to ii-1 do if b[i]=b[ii] then check:=false;
  end;
procedure comb(po:longint);
var i,j:longint;
  begin
    if po>k then
      begin
        a:=1;
        for j:=1 to k do a:=a*p[b[j]];
        pt:=pt+(a*(n-k));
        m:=m+1;
      end
      else for i:=1 to n do
             begin
               b[po]:=i;
               if check(po) then comb(po+1);
             end;
  end;
begin
m:=0;
pt:=0;
assign(d,'dezastru.in');assign(o,'dezastru.out');
reset(d);rewrite(o);
read(d,n);readln(d,k);
for i:=1 to n do read(d,p[i]);
comb(1);
pt:=pt/m;
write(o,pt:7:6);
close(o);close(d);
end.