Cod sursa(job #574470)

Utilizator dica69Alexandru Lincan dica69 Data 7 aprilie 2011 10:58:18
Problema Dezastru Scor 70
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.63 kb
var a:array[1..25] of real;
    x:array[0..25] of byte;
    s,t:real;
    n,k,h:byte;
    i,j,z:longint;


procedure back(p:byte);
var i:byte;
begin
for i:=x[p-1]+1 to n-k+p do
begin
x[p]:=i;
s:=s*a[x[p]];
if p=k then t:=t+s
       else back(p+1);
s:=s/a[x[p]];
end;
end;


begin
assign(input,'dezastru.in');
reset(input);
assign(output,'dezastru.out');
rewrite(output);
readln(n,k);
for i:=1 to n do read(a[i]);
s:=1;t:=0;

back(1);
h:=n-k;

i:=2;j:=2;z:=2;
while z<=n do
begin
if i<=k then
begin
t:=t*i;
inc(i);
end;
if j<=h then
begin
t:=t*j;
inc(j);
end;
t:=t/z;
inc(z);
end;
writeln(t:0:6);
end.