Cod sursa(job #1396464)

Utilizator teoceltareconstantin teodor teoceltare Data 22 martie 2015 16:09:13
Problema Dezastru Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("dezastru.in");
ofstream fout("dezastru.out");
int n,k,t,vec[30];
float v[30];
long long tot;
void citire()
{
    fin>>n>>k;
    for(int a1=1;a1<=n;a1++)
    {
        fin>>v[a1];
    }
}
void sum()
{
    long long sum1=1000000;
    for(int a1=1;a1<=k;a1++)
    {
        sum1*=v[vec[a1]];
    }
    tot+=sum1;
    t++;
}
void fct(int x,int pre)
{
    if(x==k) sum();
    else
    {
        x++;
        for(int a1=pre+1;a1<=n;a1++)
        {
            vec[x]=a1;
            fct(x,a1);
        }
    }
}
int main()
{
    citire();
    fct(0,0);
    tot/=t;
    int nr;
    nr=tot/1000000;
    tot%=1000000;
    fout<<nr<<"."<<tot;

}