Cod sursa(job #743260)

Utilizator ephgstefana gal ephg Data 3 mai 2012 20:27:40
Problema Dezastru Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <cstdio>
int a[30],n,k,c;
double s[30],poz;
void perm(int i){
	int j;
	double pp;
	for(j=a[i-1]+1;j<=n;++j){
		pp=1;
		a[i]=j;
		if(i==k){
			for(int x=1;x<=k;++x){
				pp*=s[a[x]];
			}
			++c;
			poz+=pp;
		}
		else perm(i+1);
	}
}
int main () {
	int i;
	freopen("dezastru.in","r",stdin);
	freopen("dezastru.out","w",stdout);
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;++i)scanf("%lf",&s[i]);
	perm(1);
	double pf=poz/(double)c;
	printf("%lf",pf);
	return 0;
}