Cod sursa(job #2431127)

Utilizator Andrei.GheorgheAndrei Gheorghe Andrei.Gheorghe Data 18 iunie 2019 11:17:04
Problema Dezastru Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include<fstream>
using namespace std;
ifstream cin("dezastru.in");
ofstream cout("dezastru.out");
int st[1000],n,k,i,o,perm=0;
bool valid, succesor;
float v[1000],pe,p=1;
int main()
{
    k=1;
    cin>>n>>o;
    for(i=1;i<=n;i++)cin>>v[i];
    while(k)
    {
        do{
                valid=1;
        if(st[k]<n)
        {
            st[k]++;
            succesor=1;
        }else succesor=0;
        if(succesor)
        for(i=1;i<k;i++)
        {
            if(st[i]==st[k])
            {
                valid=0;
            }
        }
        }while(!valid&&succesor);
        if(succesor)
        {
            if(k==n)
            {
                p=1;
                for(i=1;i<=o;i++)
                {
                    p=p*v[st[i]];
                }
                perm++;
                pe=pe+p;
            }
            else
            {
                k++;st[k]=0;
            }
        }
        else k--;
    }
    cout<<pe/perm;
}