Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一直在re,请问是怎么回事。。。import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); while (true) { String ss = s.nextLine(); if (ss.equals("0")) { s.close(); return; } String[] sp = ss.split(" "); int c = Integer.valueOf(sp[0]); int n = Integer.valueOf(sp[1]); int m = Integer.valueOf(sp[2]); if (c == 0) { if (m != 0) System.out.println("0.000"); else System.out.println("1.000"); continue; } if (m > c || m > n) { System.out.println("0.000"); continue; } if (m == 0 && n == 0) { System.out.println("1.000"); continue; } float[][] dp = init(c, n, m); System.out.println(String.format("%.3f", dp[n][m])); } } static float[][] init(int c, int n, int m) { if (n > 1000) n = 1000 + n % 2; float[][] dp = new float[n + 1][c + 2]; dp[0][0] = 1.0f; for (int i = 1; i <= n; ++i) { dp[i][0] = dp[i - 1][1] / (float) c; dp[i][c] = dp[i - 1][c - 1] / (float) c; for (int j = 1; j < c; ++j) { if ((j + i) % 2 == 1) continue; dp[i][j] = (dp[i - 1][j + 1] * (float) (j + 1) + dp[i - 1][j - 1] * (float) (c + 1 - j)) / (float) c; } } return dp; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator