zoukankan      html  css  js  c++  java
  • poj2030

    递推

    View Code
    import java.math.BigInteger;
    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            Scanner cin = new Scanner(System.in);
            while (true) {
                int n, m;
                m = cin.nextInt();
                n = cin.nextInt();
                if (n == 0 && m == 0)
                    return;
                String[] map = new String[n];
                for (int i = 0; i < n; i++)
                    map[i] = cin.next();
                BigInteger[][] f = new BigInteger[n][m];
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < m; j++)
                        if (map[i].charAt(j) >= '0' && map[i].charAt(j) <= '9') {
                            BigInteger temp = BigInteger.valueOf((int) (map[i]
                                    .charAt(j) - '0'));
                            f[i][j] = temp;
                            if (j - 1 >= 0) {
                                BigInteger a = f[i][j - 1].multiply(
                                        BigInteger.valueOf(10)).add(temp);
                                if (f[i][j].compareTo(a) < 0)
                                    f[i][j] = a;
                            }
                            if (i - 1 >= 0) {
                                BigInteger a = f[i - 1][j].multiply(BigInteger.valueOf(10))
                                        .add(temp);
                                if (f[i][j].compareTo(a) < 0)
                                    f[i][j] = a;
                            }
    //                        System.out.println(i + " " + j + " " + f[i][j]);
                        } else
                            f[i][j] = BigInteger.ZERO;
                BigInteger ans = BigInteger.ZERO;
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < m; j++)
                        if (ans.compareTo(f[i][j]) < 0)
                            ans = f[i][j];
                System.out.println(ans);
            }
        }
    }
  • 相关阅读:
    LintCode: Climbing Stairs
    LintCode: Binary Tree Postorder Traversal
    LintCode: Binary Tree Preorder Traversal
    LintCode: Binary Tree Inorder Traversal
    Lintcode: Add Two Numbers
    Lintcode: Add Binary
    LintCode: A + B Problem
    LintCode: Remove Linked List Elements
    LintCode:Fibonacci
    Lintcode开刷
  • 原文地址:https://www.cnblogs.com/rainydays/p/2984625.html
Copyright © 2011-2022 走看看