Cod sursa(job #1740554)

Utilizator anisca22Ana Baltaretu anisca22 Data 11 august 2016 18:48:29
Problema Dezastru Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("dezastru.in");
ofstream fout("dezastru.out");
int n,k,nr,fol[100],vec[100];
double a[100],S,p;
void bk(int i){
    if(i>k)
    {
        nr++;
        p=1;
        for(int j=1;j<=k;j++)
        {
            p=p*a[vec[j]] ;
        }
        S=S+p;
        return;
    }
    for(int j=1;j<=n;j++)
    {
        if(fol[j]==0)
        {
            vec[i]=j;
            fol[j]=1;
            bk(i+1);
            fol[j]=0;
        }
    }
}
int main()
{
    //(づ°ω°)づ (づ°ω°)づ (づ°ω°)づ
    fin>>n>>k;
    for(int i=1;i<=n;i++)
        {
        fin>>a[i];

        }
    bk(1);
    fout<<S/nr<<"\n";
    //(づ°ω°)づ (づ°ω°)づ (づ°ω°)づ
    return 0;
}