Cod sursa(job #1533534)

Utilizator Y0da1NUME JMECHER Y0da1 Data 22 noiembrie 2015 17:46:26
Problema Dezastru Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <iostream>
#include <fstream>
using namespace std;
ofstream out ("dezastru.out");
ifstream in ("dezastru.in");
int n, k, st[26], c, nr=0;
double a[26], s=0, p=1;
int succesor()
{
    if (st[k]<n)//pui aici cate nr
    {
        st[k]++;
        return 1;
    }
    else
        return 0;
}
int sol()
{
    return (k==c);
}
void tipar()
{
    p=1;
    nr++;
    for(int i=1;i<=c;i++)
        {
            p*=a[st[i]];
        }
    s+=p;

}
void bk()
{
    int as;
    k=1;
    st[k]=0;
    while(k>0)
    {
    as=succesor();
    if (as)
        if (sol())
            tipar();
        else
        {
            k++;
            st[k]=st[k-1];
        }
    else k--;
    }
}
int main()
{
    int i;
    in>>n>>c;
    for(i=1;i<=n;i++)
        in>>a[i];
    bk();
    out<<(double)s/nr;
    in.close();
    out.close();
    return 0;
}