1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution { public long sellingWood(int m, int n, int[][] prices) { int[][] pr = new int[m + 1][n + 1]; for (int[] p : prices) { pr[p[0]][p[1]] = p[2]; } long[][] f = new long[m + 1][n + 1]; for (int i = 1; i <= m; ++i) { for (int j = 1; j <=n; ++j) { f[i][j] = pr[i][j]; for (int k = 1; k < j; ++k) f[i][j] = Math.max(f[i][j], f[i][k] + f[i][j - k]); for (int k = 1; k < i; ++k) f[i][j] = Math.max(f[i][j], f[k][j] + f[i - k][j]); } } return f[m][n]; } }
|