Pagini recente » Cod sursa (job #756438) | Cod sursa (job #1995456) | Cod sursa (job #652899) | Cod sursa (job #1526207) | Cod sursa (job #2119619)
#include <fstream>
#include <iomanip>
#define NMAX 30
using namespace std;
ifstream fin ("dezastru.in");
ofstream fout ("dezastru.out");
int n, m, use[NMAX], currArrangement[NMAX], noAttacks;
double v[NMAX], localChance, globalChance;
void arrange (int k)
{
int i;
if (k == m+1) {
noAttacks++;
localChance = 1;
for (i = 1; i <= m; i++) localChance *= v[currArrangement[i]];
globalChance += localChance;
}
else {
for (i = 1; i <= n; i++)
if (!use[i]) {
currArrangement[k] = i;
use[i] = 1;
arrange (k+1);
use[i] = 0;
}
}
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= n; i++) fin >> v[i];
arrange (1);
fout << fixed << setprecision(6) << globalChance / noAttacks << "\n";
return 0;
}