Cod sursa(job #690112)

Utilizator andreidanAndrei Dan andreidan Data 25 februarie 2012 11:07:20
Problema Dezastru Scor 50
Compilator cpp Status done
Runda avram_simulare_7 Marime 0.83 kb
#include<cstdio>

int V[20];
int n, k;
int frecv[20];
double numere[1000];

int eValid(int i) {
    if (V[i] > n) return 0;
    for(int j = 1; j < i; j++)
     if (V[j] == V[i]) return 0;
    return 1;
}
int main() {
	double pr=1,su=0;
	freopen("dezastru.in","r",stdin);
	freopen("dezastru.out","w",stdout);
    scanf("%d %d",&n,&k);
	for(int i = 1; i <= n; i++)
		scanf("%lf", &numere[i]);
	
    int st = 1,cont=0;
    while(st > 0) {
       V[st]++;
       if(eValid(st)) {
           if (st == k) {
			   pr=1;
               for(int i = 1; i <= k; i++){
				pr=pr*numere[V[i]];
			   }
			   su=su+pr;
			   ++cont;
           }
           else
             st++;
       }
       else
        if (V[st] > n) {
          V[st] = 0;
          st--;
        }
    }
	printf("%lf", su/cont);
    return 0;
}