Cod sursa(job #1839161)

Utilizator wilson182Alexandrina Panfil wilson182 Data 2 ianuarie 2017 15:48:08
Problema Dezastru Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include<bits/stdc++.h>
using namespace std;
int b[100],n, uz[100], j, k;
double a[100], sm=0;
long long fact(int x){
	if (x) return x*fact(x-1); else return 1;
}
int sura(){
	double s=1.0;
	for(j=1; j<=k; j++) s = s * a[b[j]];
	return s;
}
void back(int l){
	int i;
    if (l==k+1) {
    	double s=1;
        for(int j=1; j<=k; j++) s*=a[b[j]];
        sm+=s;
    }
    else for(i=1; i<=n; i++){
        if (!uz[i]){
            b[l]=i;
            uz[i]=1;
            back(l+1);
            uz[i]=0;
            }
        }
    }
int main()
{
	freopen("dezastru.in", "r", stdin);
	freopen("dezastru.out", "w", stdout);
	cin>>n>>k;
	int i;
	
	for(i=1; i<=n; i++) cin>>a[i];
	long long m=fact(n);
	back(1);
	cout<<sm/m;
	return 0;
}