Cod sursa(job #248303)

Utilizator andumMorie Daniel Alexandru andum Data 25 ianuarie 2009 12:52:03
Problema Dezastru Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <stdio.h>

int n,st[26],k,i,t;
float v[26],s;

void back(int p)
{

  int x,i;
  float q;

  if (p==k+1) {
	       q=1;
	       for (x=1;x<=p-1;x++)
		   q=q*v[st[x]];
	       s=s+q;
	       t++;
	      }
      else {
	    for (x=1;x<=n;x++)
		{
		 st[p]=x;
		 int ev=1;
		 for (i=1;i<p && ev==1;i++)
			if (st[i]==st[p]) ev=0;
		 if (ev) back(p+1);
		}
      }
}

int main()
{
 freopen("dezastru.in","r",stdin);
 freopen("dezastru.out","w",stdout);

 scanf("%d %d",&n, &k);
 for (i=1;i<=n;i++)
	scanf("%f", &v[i]);

 back(1);

 printf("%f", s/t);

 return 0;

}