Problem Descriptioni ' ve bought an orchard and decide to plant some apple trees on it. The orchard seems like an N * M two-dimensional map. In each grid, I can either plant a apple tree to get one apple or fertilize the soil to speed up its neighbors ' productio N. When a grid is fertilized, the grid itself doesn ' t produce apples and the number of apples of its four neighbor trees W Ill double (if it exists). For example, a apple tree locates on (x, Y), and (X-1, y), (x, y-1) is fertilized while (x + 1, y), (x, y + 1) is n OT, then I can get four apples from (x, y). Now, I am wondering how many apples I can get on the most in the whole orchard?
Inputthe input contains multiple test cases. The number of test cases T (t<=100) occurs in the first line of input.
For each test case, the integers N, M (1<=n, m<=100) is given in a line, which denote the size of the map.
Outputfor Each test case, you should output the maximum number of apples I can obtain.
Sample Input
22 23 3
Sample Output
832 Test instructions: One can either grow an apple number, or fertilization, fertilization, it will make it up and down the apple trees are doubled, the most possible idea: in turn, fertilizer planting tree calculation#include <iostream> #include <cstring> #include <cstdio> #include <algorithm>using namespace std;const int MAXN = 110;int map[maxn][maxn];int N, m;int cal (int i, int j) {int ans = 1; if (map[i][j+1] = = 0) ans <<= 1; if (map[i+1][j] = = 0) ans <<= 1; if (map[i-1][j] = = 0) ans <<= 1; if (map[i][j-1] = = 0) ans <<= 1; return ans;} int main () {int t; scanf ("%d", &t); while (t--) {scanf ("%d%d", &n, &m); memset (Map,-1, sizeof (map)); int flag = 0; for (int i = 1; I <= m; i++) {map[1][i] = flag; flag =!flag; } for (int i = 2, I <= N; i++) for (int j = 1; j <= M; j + +) Map[i][j] =!map[i-1][j ]; int ans = 0; for (int i = 1, i <= N; i++) for (int j = 1; j <= M; j + +) if (Map[i][j]) Ans + = cal (I, J); memset (Map,-1, sizeof (map)); flag = 1; for (int i = 1; I <= m; i++) {map[1][i] = flag; flag =!flag; } for (int i = 2, I <= N; i++) for (int j = 1; j <= M; j + +) Map[i][j] =!map[i-1][j ]; int tmp = 0; for (int i = 1, i <= N; i++) for (int j = 1; j <= M; j + +) if (Map[i][j]) TMP + = Cal (I, J); printf ("%d\n", max (ans, tmp)); } return 0;}