Cod sursa(job #1723745)

Utilizator BlackNestaAndrei Manaila BlackNesta Data 1 iulie 2016 14:51:00
Problema Dezastru Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

int n, k, b[30], p;
float a[30], s, sum;

void Citire()
{
    ifstream f("dezastru.in");
    f >> n >> k;
    for(int i = 1; i <= n; i++)
        f >> a[i];
    f.close();
}

void Calculez()
{
    s = 1;
    for(int i = 1; i <= k; i++)
        s *= a[b[i]];
    sum += s;
    p++;
}

void Generare(int top)
{
    if(top == k + 1) Calculez();
    else
    for(int i = b[top - 1] + 1; i <= n; i++)
    {
        b[top] = i;
        Generare(top + 1);
    }
}

int main()
{
    Citire();
    Generare(1);
    ofstream g("dezastru.out");
    g << sum / p << "\n";
    g.close();
    return 0;
}