Cod sursa(job #1598570)

Utilizator georgeliviuPereteanu George georgeliviu Data 12 februarie 2016 23:59:55
Problema Dezastru Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <cstdio>

using namespace std;

int k , x , y , n , v[100] , q , ap[100] ;
double cost[100] , suma , sol[100] , raspuns ;

void afisare()
{
    for ( int i = 1 ; i <= k ; i++ )
    {
        printf("%d ",v[i]);
    }
    printf("\n");
}

void bkt( int x )
{
    if ( x == n + 1 )
    {
        suma = 1 ;
        for ( int i = 1 ; i <= k ; i++ )
        {
            suma *= cost[v[i]];
        }
        ++q ;
        sol[q] = suma ;
        //afisare();
        return ;
    }
    for ( int i = 1 ; i <= n ; i++ )
    {
        if ( ap[i] != 1 )
        {
            v[x] = i ;
            ap[i] = 1 ;
            bkt ( x + 1 ) ;
            ap[i] = 0 ;

        }

    }
}

int main()
{
    freopen("combinari.in","r",stdin);
    freopen("combinari.out","w",stdout);
    raspuns = 0 ;
    scanf("%d %d",&n,&k);
    for ( int i = 1 ; i <= n ; i++ )
    {
        scanf("%lf ",&cost[i]) ;
    }
    bkt(1) ;
    for ( int i = 1 ; i <= q ; i++ )
    {
        raspuns += ( sol[i] / q ) ;
    }
    printf("%lf",raspuns);

}