Cod sursa(job #195548)

Utilizator MciprianMMciprianM MciprianM Data 19 iunie 2008 17:20:09
Problema Dezastru Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<fstream>
using namespace std;

ifstream f("dezastru.in");
ofstream g("dezastru.out");

double p[30];
int n, k;
int nfact=0;
int x[30];
double Pg=0;

int verif(int lim){
  int i;
  for(i=1;i<lim;i++)
    if(x[lim]==x[i])
      return 0;
  return 1;
}
void scrie(){
   double Pl=1.0;
   int i;
   for(i=1;i<=k;i++)
     Pl*=p[x[i]];
   Pg+=Pl;
  nfact++;
}
void back(int i){
  int j,lim=n-k+i+1;
  for(j=x[i-1]+1;j<lim;j++)
    {
	 x[i]=j;
	 if(i==k)  scrie();
	 else back(i+1);
    }
}
int main(){
  int i;
  f>>n>>k;
  for(i=1;i<=n;i++)
    f>>p[i];
  back(1);
  double rez = Pg/nfact;
  g<<rez<<'\n';
  f.close();
  g.close();
  return 0;
}