Cod sursa(job #2493322)

Utilizator bogdanbenteaBentea Bogdan bogdanbentea Data 16 noiembrie 2019 11:37:23
Problema Dezastru Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
#include <iomanip>
using namespace std;
ifstream cin("dezastru.in");
ofstream cout("dezastru.out");

int n,k,i,st[30],viz[30];
double v[30],sum;

void tipar(int vf)
{
    int j;
    double p=1.0;
    for(j=1;j<=vf;j++)
    {
        p=p*v[st[j]];
        ///cout<<p<<" ";
    }
    ///cout<<endl;
    sum+=p;
}

void bkt(int vf)
{
    int j;
    for(j=1;j<=n;j++)
    {
        if(viz[j]==0)
        {
            st[vf]=j;
            viz[j]=1;
            if(vf==k)
                tipar(vf);
            else
                bkt(vf+1);
            viz[j]=0;
        }
    }
}

int main()
{
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    bkt(1);
    for(i=2;i<=n;i++)
        sum/=i;
    cout<<setprecision(6)<<sum;
    ///cout<<sum;
    return 0;
}