Pagini recente » Cod sursa (job #2381258) | Cod sursa (job #1366383) | Cod sursa (job #2117232) | Cod sursa (job #636630) | Cod sursa (job #169792)
Cod sursa(job #169792)
{ http://infoarena.ro/problema/dezastru }
type matrice=array[0..25,0..25] of extended;
var f,g:text;
a:matrice;
c:longint;
q:boolean;
n,m,i,j:byte;
p:array[1..25] of real;
function fact(n:byte):longint;
begin
if n=0 then fact:=1
else fact:=n*fact(n-1);
end;
BEGIN
assign(f,'dezastru.in'); reset(f);
assign(g,'dezastru.out'); rewrite(g);
readln(f,n,m);
for i:=1 to n do
read(f,p[i]);
a[0,0]:=1; a[1,0];
q:=true;
for i:=1 to n do
begin
a[i,0]:=1;
for j:=1 to i do
if j<=m then a[i,j]:=a[i-1,j]+a[i-1,j-1]*p[i]
else q:=false;
if not(q) then break;
end;
c:=fact(n) div fact(n-m) div fact(m);
writeln(g,a[n,m]/c:0:6);
close(f); close(g);
END.