Cod sursa(job #2682959)

Utilizator Wister1043Silaghi Razvan-Andrei Wister1043 Data 10 decembrie 2020 00:10:06
Problema Dezastru Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("dezastru.in");
ofstream fout("dezastru.out");

double v[26];
int x[26];
double prod[26];
int N,K;
double s=0;
int m;

int main()
{
    fin>>N>>K;
    for(int i=1;i<=N;i++)
    {
        fin>>v[i];
    }
    int p=1;
    prod[0]=1;
    x[p]=0;
    while(p>0)
    {
            if(x[p]<N)
            {
                x[p]++;
                prod[p]=prod[p-1]*v[x[p]];
                    if(p==K)
                    {
                        s+=prod[p];
                        m++;
                    }
                    else
                    {
                        p++;
                        x[p]=x[p-1];
                    }
            }
            else
            {
                p--;
            }
    }
    fout.precision(7);
    fout<<(s/m);
    return 0;
}