Cod sursa(job #2244807)

Utilizator eilerGabriel-Ciprian Stanciu eiler Data 23 septembrie 2018 18:40:26
Problema Dezastru Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream>
#include <iomanip>
using namespace std;

int n, k, nrp;
double p[25], rez;

void genPerm(int al, int pz, double pr){
	if (al<k){
		if (k-al<n-pz)
			genPerm(al, pz+1, pr);
		genPerm(al+1, pz+1, pr*p[pz]);
	}
	else{
		rez+=pr;
		nrp++;
	}
}

int main(){
	int i;

	ifstream fin ("dezastru.in");
	fin >> n >> k;
	for (i=0; i<n; i++)
		fin >>  p[i];
	fin.close();

	genPerm(0, 0, 1);
	rez/=nrp;

	ofstream fout ("dezastru.out");
	fout << setprecision(6) << fixed << rez;
	fout.close();

	return 0;
}