Pagini recente » Cod sursa (job #1473616) | Cod sursa (job #1448373) | Cod sursa (job #2347449) | Cod sursa (job #1825773) | Cod sursa (job #2616293)
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
ifstream fin ("dezastru.in");
ofstream fout ("dezastru.out");
int n , k;
double aranjamente[25], atacuri[25] , stotala=0, p;
bool marcat[25];
void bkt_dezastru(int pos)
{
int i;
if(pos==k)
{
p=1;
for(i=0;i<pos;i++)
p*=aranjamente[i];
cout << p << '\n';
stotala+=p;
}
else
{
for(i=0;i<n;i++)
{
if(marcat[i]==0)
{
marcat[i]=1;
aranjamente[pos]=atacuri[i];
bkt_dezastru(pos+1);
marcat[i]=0;
}
}
}
}
int main()
{
int j, nraranjamente=1;
fin >> n >> k;
for(j=0;j<n;j++)
fin >> atacuri[j];
j=n-k+1;
for(j;j<=n;j++)
nraranjamente=(long long)nraranjamente*j;
bkt_dezastru(0);
fout << setprecision(6) << stotala/nraranjamente;
return 0;
}