Pagini recente » Cod sursa (job #1347346) | Cod sursa (job #2568743) | Cod sursa (job #3237640) | Cod sursa (job #1075771) | Cod sursa (job #422994)
Cod sursa(job #422994)
#include<fstream>
#define dmax 30
using namespace std;
ifstream in("dezastru.in");
ofstream out("dezastru.out");
int n,m,cmb[dmax][dmax];
long long nr;
double x[dmax],mat[dmax][dmax],sol;
long long comb(int n,int k)
{ int i,j;
cmb[1][0]=cmb[1][1]=1;
for(i=2;i<=n;i++)
for(j=0;j<=i;j++)
{ if(j==0 || j==i)cmb[i][j]=1;
else cmb[i][j]=cmb[i-1][j-1]+cmb[i-1][j];
}
return cmb[n][k];
}
int main()
{ int i,j;
in>>n>>m;
for(i=1;i<=n;i++)
in>>x[i];
in.close();
for(i=1;i<=n;i++)
mat[i][1]=mat[i-1][1]+x[i];
for(i=2;i<=m;i++)
mat[1][i]=0;
for(i=2;i<=n;i++)
for(j=2;j<=m;j++)
mat[i][j]=mat[i-1][j]+mat[i-1][j-1]*x[i];
sol=mat[n][m]/(double)(comb(n,m));
out<<sol;
out.close();
return 0;
}