Cod sursa(job #1458851)

Utilizator cristina_borzaCristina Borza cristina_borza Data 8 iulie 2015 16:27:09
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <fstream>
#include <iomanip>

using namespace std;
ifstream f("dezastru.in");
ofstream g("dezastru.out");
long long n,k,i,j,f1,f2,f3,comb = 1 , put[50];
long double a[50],mat[50][50];
int main()
{
    f >> n >> k ;
    for(int i = 1 ; i <= n ; ++i){
        f >> a[i];
    }
    for(int i = 1 ; i <= n ; ++i){
        int x = i ;
        int p = 2 ;
        while(p <= x){
            while(x % p == 0){
                x /= p ;
                ++put[p] ;
            }
            ++p ;
        }
    }

    for(int i = 1 ; i <= k ; ++i){
        int x = i ;
        int p = 2 ;
        while(p <= x){
            while(x % p == 0){
                x /= p ;
                --put[p] ;
            }
            ++p ;
        }
    }

    for(int i = 1 ; i <= n - k ; ++i){
        int x = i ;
        int p = 2 ;
        while(p <= x){
            while(x % p == 0){
                x /= p ;
                --put[p] ;
            }
            ++p ;
        }
    }
    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= put[i] ; ++j){
            comb = comb * i ;
        }
    }
    for(i = 0 ; i <= n; ++i)
    {
        mat[i][0]=1;
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
            mat[i][j]=mat[i-1][j]+mat[i-1][j-1]*a[i];
    }
    g<<fixed<<setprecision(6)<<mat[n][k]/comb<< '\n';
    return 0;
}