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 了,高兴死了 - - - - - - -给出关键部分代码: void run() { int n = in.nextInt(); int m = in.nextInt(); boolean[][] maps = new boolean[n][]; for (int i = 0; i < n; i++) { maps[i] = new boolean[i + 1]; for (int j = 0; j <= i; j++) { maps[i][j] = in.next().charAt(0) == '*'; } } Rational[][] dp = new Rational[n + 1][]; dp[0] = new Rational[1]; dp[0][0] = Rational.ONE; for (int i = 1; i <= n; i++) { dp[i] = new Rational[i + 1]; for (int j = 0; j <= i; j++) { dp[i][j] = Rational.ZERO; if (j > 0 && maps[i - 1][j - 1]) { dp[i][j] = dp[i][j].add(dp[i - 1][j - 1].div(Rational.TWO)); } if (j < i && maps[i - 1][j]) { dp[i][j] = dp[i][j].add(dp[i - 1][j].div(Rational.TWO)); } if (j > 0 && j < i && !maps[i - 2][j - 1]) { dp[i][j] = dp[i][j].add(dp[i - 2][j - 1]); } } } out.println(dp[n][m]); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator