Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.RoundingMode;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class C {
- public static void main(String[] args) {
- int n = 0;
- int m = 0;
- int k = 0;
- double[][] probDistribution = new double[2][9];
- try (Scanner sc = new Scanner(System.in)) {
- n = sc.nextInt();
- m = sc.nextInt();
- k = sc.nextInt();
- }
- probDistribution[1][0] = 1;
- for (int i = 1; i <= k; i++) {
- int last = Math.min(m * n, i) - 1;
- probDistribution[1][last] = 1;
- for (int j = 0; j < last; j++) {
- if (j == 0) {
- probDistribution[1][j] /= (m * n);
- } else {
- double one = probDistribution[0][j - 1] * (m * n - j) / (m * n);
- double two = probDistribution[0][j] * (j + 1) / (m * n);
- probDistribution[1][j] = one + two;
- }
- probDistribution[1][last] -= probDistribution[1][j];
- }
- for (int j = 0; j < i; j++) {
- probDistribution[0][j] = probDistribution[1][j];
- }
- }
- double expectedValue = 0;
- int maxTarget = Math.min(k, m * n);
- for (int i = 0; i < maxTarget; i++) {
- double v = (i + 1d) * probDistribution[0][i];
- expectedValue += v;
- }
- System.out.println(printDoubleJava(expectedValue));
- }
- public static String printDoubleJava(double d) {
- DecimalFormat df = new DecimalFormat("0.000000000000");
- df.setRoundingMode(RoundingMode.HALF_UP);
- return df.format(d);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement