-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdice.java
More file actions
executable file
·37 lines (31 loc) · 864 Bytes
/
dice.java
File metadata and controls
executable file
·37 lines (31 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Jaskaren Saini
// Uvic Id - V00877182
import java.util.*;
public class dice{
static int n, s, k;
static Double[][] array;
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
s = scan.nextInt();
k = scan.nextInt();
array = new Double[n+1][s+1];
System.out.println(Prob(n, 0));
}
public static double Prob(int numthrows, int num) {
if (num >= k) {
return 1.0;
}
if (numthrows == 0) {
return 0.0;
}
if (array[numthrows][num] != null) {
return array[numthrows][num];
}
double probold = (double) num / (double) s;
double probnew = 1.0 - probold;
double probability = probnew * Prob(numthrows - 1, num + 1) + probold * Prob(numthrows - 1, num);
array[numthrows][num] = probability;
return array[numthrows][num];
}
}