Pagini recente » Cod sursa (job #3179863) | Cod sursa (job #1005254) | Cod sursa (job #2916420) | Cod sursa (job #1541557) | Cod sursa (job #884115)
Cod sursa(job #884115)
#include<fstream>
using namespace std;
ifstream f("dezastru.in");
ofstream g("dezastru.out");
int a[26],n,m,nr;
float x[26],s=0,p;
void gen(int k)
{
int i,j;
if(k==m+1)
{
nr++;
p=1;
for(j=1;j<=m;j++)
p=p*x[a[j]];
s=s+p;
}
else
for(i=a[k-1]+1;i<=n;i++)
{
a[k]=i;
gen(k+1);
}
}
int main()
{
f>>n>>m;
for(int i=1;i<=n;i++)
f>>x[i];
a[0]=0;
gen(1);
//g<<nr<<"\n"<<s<<"\n";
s=s*2;
nr=nr*2;
g<<s/nr;
return 0;
}