Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4925
Apple TreeTime
limit:2000/1000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 176 Accepted Submission (s): 120
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
Source2014 multi-university Training Contest 6
The code is as follows:
#include <cstdio> #include <cstring> int mp[217][217];int main () {int t; int n,i,a,ans,k,er,m,j; while (scanf ("%d", &t)!=eof) {while (t--) {scanf ("%d%d", &n,&m); Memset (Mp,0,sizeof (MP)), if (n = = 1 && m = = 1) {printf ("1\n"); continue;} for (i = 1; I <= N, i++) {for (j = 1; j <= M; j + +) {if ( I+J) &1) mp[i][j]=1; }} ans=0; for (i = 1; I <= N, i++) {for (j = 1; j <= M; j + +) {if (M P[I][J] = = 0) {if (Mp[i-1][j]) { mp[i-1][j]*=2; } if (Mp[i][j-1]) {mp[i][j-1]*=2; } if (mp[i][j+1]) {mp[i][j+1]*=2; } if (Mp[i+1][j]) {mp[i+1][j]*=2; }}}} for (i = 1; I <= n; i++) {for (j = 1; j <= M; j + +) {if (Mp[i][j]) ANS+=MP[I][J]; }} printf ("%d\n", ans); }} return 0;}