Pagini recente » Cod sursa (job #3290994) | Cod sursa (job #2214796) | Cod sursa (job #3283965) | Cod sursa (job #2795863) | Cod sursa (job #3288312)
#include <fstream>
using namespace std;
ifstream cin ("dezastru.in");
ofstream cout ("dezastru.out");
int x[26],n,p,nrperm,i;
double v[26],s;
void back(int k, double prod)
{
for(int i=x[k-1]+1;i<=n;++i){
x[k]=i;
if(k==p){
s=s+prod*v[x[k]];
nrperm++;
}
else
back(k+1, prod*v[x[k]]);
}
}
int main()
{
cin>>n>>p;
for(i=1;i<=n;++i)
cin>>v[i];
back(1, 1);
cout<<(double)s/nrperm;
return 0;
}