Cod sursa(job #155826)

Utilizator Andrei_ScorpioAndreiana Andrei Daniel Andrei_Scorpio Data 12 martie 2008 10:40:12
Problema Dezastru Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include<fstream.h>
ifstream f("dezastru.in");
ofstream g("dezastru.out");
int x[30],k,n,m,vec[31],i;
double S,a[30],nr,P;
int main()
{
f>>n>>m;
for(i=1;i<=n;i++)
    f>>a[i];
k=1;
x[k]=0;
P=1;
while(k>0)
    {
    if(x[k]<n-m+k)
	{
	x[k]++;
	if(vec[x[k]]==0)
	    {
	    if(k==m)
		{
		P*=a[x[k]];
		S+=P;
		nr++;
		P/=a[x[k]];
		}
	    else
		{
		vec[x[k]]=1;
		P*=a[x[k]];
		k++;
		x[k]=x[k-1];
		}
	    }
	}
    else
	{
	k--;
	if(k>0)
		P/=a[x[k]];
	vec[x[k]]=0;
	}
    }
g<<S/nr<<'\n';
g.close();
return 0;
}