Cod sursa(job #345935)

Utilizator georgelRector George georgel Data 5 septembrie 2009 17:29:45
Problema Dezastru Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<fstream>

using namespace std;
ofstream fout("dezastru.out");

int n,k,x[15],cant;
float a[25],s=1,dezastru=0;
void read(){
ifstream fin("dezastru.in");
fin>>n>>k;
for(int i = 1; i <= n; i++)
fin>>a[i];
fin.close();
}
void adun(){
     for(int i = 1; i <= k;i++)
             s*=a[x[i]];
     dezastru+=s;
     s=1;
     cant++;
}
void comb(int p){
     int i;
     for(i=x[p-1]+1; i <= n-k+p;i++)
     {
                     x[p] = i;
                     if(p == k)
                          adun();
                     else comb(p+1);
     }
}
int main(){
    read();
    comb(1);
    fout<<dezastru/cant;
fout.close();
return 0;
}