Cod sursa(job #2480088)

Utilizator tomaionutIDorando tomaionut Data 24 octombrie 2019 21:15:40
Problema Dezastru Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("dezastru.in");
ofstream fout("dezastru.out");
int n,k;
float s,vs1[30],sol,z[30];
int a[30],v[30],cnt;
void add()
{
    float s1=1;
    for (int i=1; i<=k; i++)
        s1*=z[a[i]];
    vs1[++cnt]=s1;
}
void Back(int top)
{
    if (top==k+1)
        add();
    else for (int i=1; i<=n; i++)
        if (v[i]==0)
    {
        a[top]=i;
        v[i]=1;
        Back(top+1);
        v[i]=0;
    }

}
int main()
{
   int i;
   fin >> n >> k;
   for (i=1; i<=n; i++)
    fin >> z[i];
   Back(1);
   for (i=1; i<=cnt; i++)
   s+=vs1[i];
   sol=(s*1.0)/cnt;
   fout << setprecision(6) << fixed << sol;



    return 0;
}