Title: Hdu4925apple Tree (Law-seeking)
The main idea: give the matrix of N M, and then each lattice or apple, or fertilization: After (x, y) fertilization, its upper and lower apple tree yield will double. The number of apples was planted and the yield was 1. The maximum number of apples that can be obtained by such a n * M matrix.
Problem Solving Ideas:
For the 2 * 2 matrix: X for fertilization, and the number for Tree x 2 is the best. The respective numbers represent the lattice being fertilized several times. Then 2 * 2 of the maximum number of apples 2 ^2 + 2^2 = 8;
2 X
3 * 3:x 3 X
3 X 3
X 3 x 4 * 2^3 = 32;
Find the law: The first line is the first to get fertilizer, every time from the first row of the 2nd start to find, it up and down on each side of the fertilization, so that it can maximize the impact of its output, yield 2^n (up and down the number of squares), and fertilization where to mark the next time you can not plant trees here. Look back and get the total output.
Code:
#include <cstdio> #include <cstring>const int N = 105;const int M = 4;int visit[n][n];const int dir[m][2] = {{0 ,-1}, {-1, 0}, {0, 1}, {1, 0}};int main () {int t;int n, m;int ans, temp;scanf ("%d", &t), while (t--) {scanf ("%d%d", &n, &m); memset (visit, 0, sizeof (visit)); Visit[0][0] = 1;ans = 0;for (int i = 0; i < n; i++) for (int j = 0; j < m; J + +) {if (visit[i][j]) continue;temp = 0;for (int k = 0; k < M; k++) {if (i + dir[k][0] >= 0 && i + dir[k][0] < n && j + dir[k][1] >= 0 && j + dir[k][1] < m) {temp++;visit[i + dir[k][0]][j + dir[k][1]] = 1; }}ans + = 1<<temp;} if (!ans) printf ("1\n"); elseprintf ("%d\n", ans);} return 0;}