Cod sursa(job #1238066)

Utilizator Alex_dudeDudescu Alexandru Alex_dude Data 5 octombrie 2014 16:12:30
Problema Dezastru Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <stdio.h>
#define nmax 25

using namespace std;
int n,m,x[nmax],ar;
double probabilitate,sol[nmax];
int fact(int x)
{
    return (x>1)?x*(fact(x-1)):1;
}
int calc()
{
    int i;
    float p=1;
    for(i=1;i<=m;i++)
        p*=sol[x[i]];
    probabilitate+=p/ar*fact(m);
}
void back(int k)
{
    int i;
    if(k>m)calc();
    else
        for(i=k;i<=n;i++)
        if(i>x[k-1])
    {
        x[k]=i;
        back(k+1);
    }
}
int main()
{
    int i;
    freopen("dezastru.in","r",stdin);
    freopen("dezastru.out","w",stdout);
  scanf("%d%d",&n,&m);
  ar=fact(n)/fact(n-m);
  for(i=1;i<=n;i++)scanf("%lf",&sol[i]);
  back(1);
  printf("%lf",probabilitate);
  return 0;
}

//Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.