Pagini recente » Cod sursa (job #1372575) | Cod sursa (job #1637274) | Cod sursa (job #2497277) | Cod sursa (job #126360) | Cod sursa (job #164462)
Cod sursa(job #164462)
#include <fstream.h>
#include <stdio.h>
int sol[30],n,kk;
long nr;
double fact,fact2;
double v[30],st,p,sm;
/*int cond(int a){
for (int i=0;i<a;i++)
if (sol[i]==sol[a]) return 0;
return 1;
}
double calc(int a){
double p=1;
for (int i=1;i<=a;i++)
p*=v[sol[i]];
return p;
}
*/
int main(){
ifstream f("dezastru.in");
freopen("dezastru.out","w",stdout);
int k;
f>>n;
int i;
f>>kk;
for ( i=1;i<=n;i++) f>>v[i];
v[n+1]=1;v[0]=1;
k=1;sol[k]=1;p=v[sol[k]];
while (k>0){
if (sol[k]>n-(kk-k)) {k--;p/=v[sol[k]]; sol[k]++;
if (sol[k]<=n-(kk-k)) p*=v[sol[k]];
}
else if (k==kk) {/*st+=calc(k);*/sm+=p;sol[k]++;nr++;
p/=v[sol[k]-1];
if (sol[k]<=n-(kk-k)) p*=v[sol[k]];
}
else if (k<n) {sol[++k]=sol[k-1]+1; p*=v[sol[k]];}
}
//st/=nr;
sm/=nr;
printf("%lf",sm);
f.close();
return 0;
}