Cod sursa(job #345937)

Utilizator georgelRector George georgel Data 5 septembrie 2009 17:30:59
Problema Dezastru Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<fstream>

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

int n,k,x[26],cant;
float a[26],s,dezastru;
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(){
    s=1;
    read();
    comb(1);
    fout<<dezastru/cant;
fout.close();
return 0;
}