package question;import java.util.Arrays;/*** @author Roderland* @since 1.0*/public class Question304 {public static void main(String[] args) {int[][] ints = {{3, 0, 1, 4, 2},{5, 6, 3, 2, 1},{1, 2, 0, 1, 5},{4, 1, 0, 1, 7},{1, 0, 3, 0, 5}};NumMatrix numMatrix = new Question304().new NumMatrix(ints);}class NumMatrix {int[][] dp;public NumMatrix(int[][] matrix) {if (matrix.length == 0) return;dp = new int[matrix.length][matrix[0].length + 1];for (int i = 0; i < dp.length; i++) {for (int j = 1; j < dp[i].length; j++) {dp[i][j] = dp[i][j - 1] + matrix[i][j - 1];}}System.out.println(Arrays.deepToString(dp));}public int sumRegion(int row1, int col1, int row2, int col2) {int sum = 0;for (int i = row1; i <= row2; i++) {sum += dp[i][col2 + 1] - dp[i][col1];}return sum;}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。