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 |
又 1A 了,好高兴啊 - - - - - -贴一个关键部分代码: private void solve(int c, int n, int m) { if (m < 0 || m > c) { out.println("0.000"); return ; } double[][] mat = new double[c + 1][c + 1]; for (int j = 0; j <= c; j++) { if (j > 0) mat[j - 1][j] = (c - j + 1.0) / c; if (j < c) mat[j + 1][j] = (j + 1.0) / c; } double[][] ini = new double[c + 1][c + 1]; ini[0][0] = 1; mat = Matrix.pow(mat, n); out.printf("%.3f%n", Matrix.mul(ini, mat)[0][m]); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator