Pagini recente » Cod sursa (job #545377) | Cod sursa (job #196916) | Cod sursa (job #597902) | Cod sursa (job #2678939) | Cod sursa (job #2493423)
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
ifstream fin("dezastru.in");ofstream fout("dezastru.out");
vector<double>v;
vector<double>rez;
vector<double>::iterator it;
int n,k,st[30],nrp;
double val=0,s=0;
bool validare(int niv)
{
int i;
for(i=1;i<niv;i++)
{
if(st[niv]==st[i])
return 0;
}
return 1;
}
bool is_solutie(int niv)
{
if(niv==k)
return 1;
else
return 0;
}
void prd(int niv)
{
double p=1;
for(int i=1;i<=niv;i++)
{
p*=(double)v[st[i]];
}
rez.push_back(p);
}
void bck(int niv,double p)
{
int i;
for(i=st[niv-1]+1;i<=n;i++)
{
st[niv]=i;
if(validare(niv)==1)
{
if(is_solutie(niv)==1)
{
s+=p*v[st[niv]];
nrp+=1;
}else
{
bck(niv+1,p*v[st[niv]]);
}
}
}
}
int main()
{
fin>>n>>k;
v.push_back(0);rez.push_back(0);
for(int i=1;i<=n;i++)
{
double x;fin>>x;
v.push_back(x);
}
bck(1,1);
fout<<fixed<<setprecision(6)<<s/nrp;
}