Cod sursa(job #308654)

Utilizator kolapsysPostelnicu Dan Marian kolapsys Data 28 aprilie 2009 01:25:09
Problema Dezastru Scor 100
Compilator fpc Status done
Runda tot Marime 0.91 kb
{ http://infoarena.ro/problema/dezastru }
type matrice=array[0..25,0..25] of extended;
var f,g:text;
    a:matrice;
    c:int64;
    n,m,i,j:byte;
    p:array[1..25] of real;
function fact(a,b:byte):int64;
var i:byte;
    p:int64;
begin
     p:=1;
     for i:=a to b do
        p:=p*i;
     fact:=p;
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]:=1;
        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 break;
            end;
        if m>n div 2 then c:=fact(m+1,n)div fact(1,n-m)
                     else c:=fact(n-m+1,n)div fact(1,m);
        writeln(g,a[n,m]/c:0:6);
        close(f); close(g);
END.