Pagini recente » Cod sursa (job #1945899) | Cod sursa (job #2902050) | Cod sursa (job #2207621) | Cod sursa (job #1116876) | Cod sursa (job #1842511)
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
class Main{
public static void main(String[] args) {
File file = new File("dezastru.in");
double[][] mat = null;
double[] p = null;
int n = 0,k = 0;
try {
Scanner sc = new Scanner(file);
if(sc.hasNextInt()) {
n = sc.nextInt();
}
if(sc.hasNextInt()) {
k = sc.nextInt();
}
p = new double[n];
mat = new double[n][n];
int i = 0;
while(sc.hasNextDouble()) {
p[i] = sc.nextDouble();
i++;
}
sc.close();
}
catch(FileNotFoundException e) {
e.printStackTrace();
}
mat[0][0] = p[0];
for(int i = 1; i < n; i++) {
mat[i][0] = mat[i-1][0] + p[i];
}
for(int i = 1; i < n; i++) {
for(int j = 1; j < n; j++) {
if(i != 0 && j != 0) {
if(j > i)
mat[i][j] = 0;
else {
mat[i][j] = mat[i-1][j] + mat[i-1][j-1] * p[i];
}
}
}
}
int prob = 1;
for(int i = k+1; i <= n; i++)
prob *= i;
/*
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
System.out.print(mat[i][j] + " ");
}
System.out.println("");
}*/
//System.out.println(mat[n-1][k-1] / prob);
try {
PrintWriter wr = new PrintWriter("dezastru.out");
wr.println(mat[n-1][k-1] / prob);
wr.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}