Pagini recente » Cod sursa (job #1888003) | Cod sursa (job #873444) | Cod sursa (job #31840) | Cod sursa (job #3280232) | Cod sursa (job #178147)
Cod sursa(job #178147)
#include<stdio.h>
FILE *in=fopen("dezastru.in","r"),*out=fopen("dezastru.out","w");
int n,k,nr=1,i,st[30],ok=0;
double s=0,v[30],mat[26][26];
void bktr(int p)
{
for(float pval=st[p-1]+1;pval<=n;pval++)
{
st[p]=pval;
if(p==k)
{
mat[nr][0]=1;
for(int x=1;x<=k;x++)
{
mat[nr][0]*=v[st[x]];
}
nr++;ok=1;
}
else bktr(p+1);
}
}
int main()
{
fscanf(in,"%d %d",&n,&k);
for(i=1;i<=n;i++)
fscanf(in,"%lf ",&v[i]);
for(i=1;i<=n+1;i++)
st[i]=0;
bktr(1);
for(i=1;i<=nr;i++)
s+=mat[i][0];
if(!ok)
fprintf(out,"%.6lf",s/nr);
else {nr--;fprintf(out,"%.6lf",s/nr);}
fcloseall();
return 0;
}