Cod sursa(job #3218299)

Utilizator Darius1414Dobre Darius Adrian Darius1414 Data 26 martie 2024 19:06:14
Problema Dezastru Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <deque>
#define nmx 30
using namespace std;
ifstream f ("dezastru.in");
ofstream g ("dezastru.out");
int n,k,m,a,b,s,v[nmx],vf[nmx],ct;
float p[nmx];
float rsp;
void co (int poz,int st,float treb)
{
    if (poz==k+1)
    {
        rsp+=treb;
        ct++;
        return;
    }
    for (int i=st; i<=n; i++)
    {
        if (!vf[i])
        {
            vf[i]=1;
            co(poz+1,i+1,treb*p[i]);
            vf[i]=0;
        }
    }
}
int main()
{
    f>>n>>k;
    for (int i=1; i<=n; i++)
        f>>p[i];
    co(1,1,1);
    g<<(float)rsp/ct;
}