Cod sursa(job #318221)

Utilizator zseeZabolai Zsolt zsee Data 27 mai 2009 18:04:38
Problema Dezastru Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.75 kb
program permutacio;

const
  maxhossz=25;

type
  index = 0..maxhossz;

var
  n,i,k,hany:byte;
  c: array[index] of byte;
  v: array[index] of real;
  be,ki:text;
  s:double;

 procedure kiiras;
 var
  i:index;
  x:real;
 begin
  x:=1;
  for i:=1 to k do
    x:=x+v[i];
  s:=s+x;
  inc(hany);
 end;

 procedure kombinacio(i: index);
 var
  j:index;
 begin
  for j:=c[i-1]+1 to n-k+i do
    begin
     c[i]:=j;
     if i<k then
       kombinacio(i+1)
     else
       kiiras;
    end;
 end;


begin
 s:=1;
 hany:=0;
 assign(be,'dezastru.in');
 assign(ki,'dezastru.out');
 rewrite(ki);
 reset(be);
 readln(be,n,k);
 for i:=1 to n do read(be,v[i]);
 kombinacio(1);
 s:=s/hany;
 writeln(ki,s);
 close(ki);
end.