HDU 4925 Apple Tree
Topic links
Test instructions: to a m*n matrix tree, each location can choose to plant trees or fertilization, if the location of the seed can not be fertilized, if fertilization can let the surrounding fruit production by 2, ask the maximum benefit
Train of thought: The inference is certainly the fruit tree and the fertilizer crosses the good, resembles the chess chessboard, the black kind, the white fertilization, because the lattice number is not many, goes directly enumerates each position to be able. If the problem is more than the number of words, can actually be introduced Formula One step to get the answer
Code:
#include <cstdio> #include <cstring>const int d[4][2] = {{0, 1}, {0,-1}, {1, 0}, {-1, 0}};int t, N, M;int main () { scanf ("%d", &t); while (t--) {scanf ("%d%d", &n, &m); int flag = 1;int ans = 0;for (int i = 0; i < n; i++) {for (int j = 0; j < m; J + +) {if (flag) { int cnt = 1; for (int k = 0; k < 4; k++) {int xx = i + d[k][0];int yy = j + d[k][1];if (xx < 0 | | xx >= n | | yy < 0 | | yy & gt;= m) continue;cnt *= 2; } ans + = cnt;} Flag ^= 1; }} printf ("%d\n", ans); } return 0;}