Pagini recente » Cod sursa (job #1819040) | Cod sursa (job #132579) | Cod sursa (job #1568909) | Cod sursa (job #228974) | Cod sursa (job #244927)
Cod sursa(job #244927)
#include<algorithm>
using namespace std;
int n,k,x,st[101];
float s,a[26];
void calc(){
int i;
float p=1;
for(i=1; i<=k; ++i)
p*=a[st[i]];
s+=p;
++x;}
void back(){
int vf,aux;
for(st[vf=1]=1; vf; ){
if(vf==k)
calc();
aux=st[vf];
if(vf==k){
if(st[vf]<n)
++st[vf];
else if(st[vf]==n){
--vf;
while(st[vf]+1>n-k+vf)
--vf;
++st[vf];}}
else if(aux+1<=n-k+vf+1)
st[++vf]=aux+1;
else if(aux+1>n-k+vf+1)
--vf;}}
void solve(){
int i;
scanf("%d%d",&n,&k);
for(i=1; i<=n; ++i)
scanf("%f",&a[i]);
back();
printf("%f",s/x);}
int main(){
freopen("dezastru.in","r",stdin);
freopen("dezastru.out","w",stdout);
solve();
return 0;}