Cod sursa(job #639828)

Utilizator oancea_horatiuOancea Horatiu oancea_horatiu Data 23 noiembrie 2011 23:44:57
Problema Dezastru Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.86 kb
var s:array[0..26] of byte;
    p:array[0..26] of real;
    t,c:real;
    i,k,n,nf:longint;
    o,d:text;
function valid(y:longint):boolean;
var i:longint;
  begin
    valid:=true;
    for i:=1 to y-1 do if s[i]=s[y] then begin valid:=false;break; end;
  end;
procedure arnj(j:longint);
var ic:longint;
  begin
    if j=k+1 then begin
                  c:=p[s[1]];
                  for i:=2 to k do c:=c*p[s[i]];
                  t:=t+c/nf;
                end
           else for ic:=1 to n do
                  begin
                    s[j]:=ic;
                    if valid(j) then arnj(j+1);
                  end;
  end;
begin
t:=0;nf:=1;
assign(d,'dezastru.in');assign(o,'dezastru.out');
reset(d);rewrite(o);
read(d,n);read(d,k);
for i:=2 to n do nf:=nf*i;
for i:=1 to n do read(d,p[i]);
arnj(1);
writeln(o,t:10:6);
close(d);close(o);
end.