Pagini recente » Cod sursa (job #1213859) | Cod sursa (job #3165964) | Cod sursa (job #1773837) | Cod sursa (job #32640) | Cod sursa (job #42412)
Cod sursa(job #42412)
#include<fstream.h>
#include<iomanip.h>
int i,np,pg,n,k,x[25],j,s,t,p;
float a[25],ok,o;
int main ()
{ ifstream f("dezastru.in");
ofstream g("dezastru.out");
f>>n>>k;
for(i=1;i<=n;i++)
f>>a[i];
np=1;
for(i=1;i<=n;i++)
np*=i;
for(i=1;i<=n;i++)
x[i]=i;
pg=1;
while (pg<=np)
{ t=1;i=n;
while(t)
{ s=x[i]+t;
x[i]=s%(n+1);
t=s/(n+1);
i--;
}
p=1;
for(j=1;j<=n;j++)
if(x[j]==0) p=0;
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
if(x[i]==x[j]) p=0;
if(p){
pg++;ok=1;
for(j=1;j<=k;j++)
ok*=a[x[j]];
o+=ok/np;
}
}
g<<setprecision(6)<<o;
g.close();
f.close();
return 0;
}