Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1A 了,高兴死了 - - - - - - -

Posted by shu_mj at 2014-08-03 00:21:27 on Problem 1189
给出关键部分代码:

    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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator