Pagini recente » Cod sursa (job #1517421) | Autentificare | Cod sursa (job #2723147) | Cod sursa (job #1711551) | Cod sursa (job #38579)
Cod sursa(job #38579)
#include <stdio.h>
#define NMAX 26
FILE *f = fopen("dezastru.in","rt"),*g = fopen("dezastru.out","wt");
double a[NMAX];
long int st[NMAX],i,j,k,fct1,fct2,n,max;
double sol,p,x;
void citire()
{
fscanf(f,"%ld %ld",&n,&k);
for (i=1;i<=n;i++)
fscanf(f,"%lf",&a[i]);
fct1=1;fct2=1;
for (i=1;i<=k;i++)
fct1=fct1*i;
for (i=1;i<=n-k;i++)
fct2=fct2*i;
max=1;
for (i=1;i<=n;i++)
max=max*i;
}
void back(long int nivel,long int nr)
{
if (nr==k) {x=(p*fct1*fct2)/max;
sol+=x;
return;}
if (nivel==n+1) return;
back(nivel+1,nr);
p*=a[nivel];
back(nivel+1,nr+1);
p/=a[nivel];
}
int main()
{
citire();
p=1;
back(1,0);
fprintf(g,"%.7lf",sol);
fclose(f);
fclose(g);
return 0;
}