Cod sursa(job #169783)

Utilizator kolapsysPostelnicu Dan Marian kolapsys Data 1 aprilie 2008 22:45:56
Problema Dezastru Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.86 kb
{ http://infoarena.ro/problema/dezastru }
type matrice=array[0..25,0..25] of real;
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]:=1;
        q:=true;
        for i:=1 to n do
            begin
            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.