Cod sursa(job #195555)

Utilizator MciprianMMciprianM MciprianM Data 19 iunie 2008 17:34:04
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include<fstream>
using namespace std;
  
ifstream f("dezastru.in");  
ofstream g("dezastru.out");  
  
double p[30];  
int n, k;  
int nfact=0;
double Pg=0;

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