Pagini recente » Monitorul de evaluare | Cod sursa (job #725496) | Cod sursa (job #2439158) | Cod sursa (job #2429880) | Cod sursa (job #2429872)
#include <fstream>
#include <iomanip>
using namespace std;
int A[30],k,n,contor;
float val[30],sum;
ifstream fin("dezastru.in");
ofstream fout("dezastru.out");
bool isValid(int pos)
{
for(int i = 1;i<pos;i++)
if(A[i]==A[pos])
return false;
return true;
}
void tipar()
{
float tmp=1.0f;
for(int i = 1;i<=k;i++)
tmp*=val[A[i]];
sum+=tmp;
contor++;
}
void backt(int pos)
{
for(int x = 1;x<=n;x++)
{
A[pos]=x;
if(isValid(pos))
{
if(pos==k)
tipar();
else
backt(pos+1);
}
}
}
int main()
{
fin>>n>>k;
for(int i = 1;i<=n;i++)
fin>>val[i];
backt(1);
float m = (float)sum/contor;
fout<<setprecision(6)<<fixed<<m;
fout.close();
return 0;
}