Pagini recente » Cod sursa (job #3269148) | Cod sursa (job #160392) | Cod sursa (job #471159) | Cod sursa (job #2043707) | Cod sursa (job #155402)
Cod sursa(job #155402)
#include <stdio.h>
#define NMax 30
int n, k;
double p[NMax][NMax], pos[NMax][NMax];
void citire();
void rez();
int main()
{
citire();
rez();
return 0;
}
void rez()
{
int l, x, y, suma = 0;
double prod = 0;
for (l=2; l<=k; l++)
{
// siruri de lungime l din l - 1
for (x=1; x<=n; x++)
{
// pun pe ultima pozitie nr X
suma = 0;
for (y=1; y<x; y++)
{
if (pos[y][l-1])
{
p[x][l] += (p[y][l-1] * pos[y][l-1]);
suma += pos[y][l-1];
pos[x][l] += pos[y][l-1];
}
}
if ( suma != 0 )
p[x][l] = p[x][l] * p[x][1] / suma;
else
p[x][l] = 0;
//p[x][l] = p[x][l] * p[x][1] / (x - 1);
}
}
suma = 0;
for (x=1; x<=n; x++)
{
suma += pos[x][k];
prod += p[x][k] * pos[x][k];
}
printf( "%.6lf\n", prod / suma );
}
void citire()
{
int i;
freopen( "dezastru.in", "rt", stdin );
freopen( "dezastru.out", "wt", stdout );
scanf( "%d %d", &n, &k );
for (i=1; i<=n; i++)
{
scanf( "%lf", &p[i][1] );
pos[i][1] = 1;
}
}