http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree
Time limit:2000/1000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): Accepted submission (s): 82
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 Input22 23 3
Sample Output832
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 intN;6 intMain ()7 {8 intn,m,map[ $][ $],i,j,t;9scanf"%d",&t);Ten while(t--) One { Ascanf"%d%d",&n,&m); -memset (Map,0,sizeof(map)); - for(i=1; i<=n;i++) the { - for(j=1; j<=m;j++) - { -map[i][j]=-1; + if((i%2==1) && (j%2==1)) -map[i][j]=1; + if((i%2==0) && (j%2==0)) Amap[i][j]=1; at } - } - - intb; - for(i=1; i<=n;i++) - for(j=1; j<=m;j++) in { - if(map[i][j]==1) to { + if(map[i-1][j]==-1&&i-1>=1) - { themap[i][j]*=2; * $ }Panax Notoginseng if(map[i][j-1]==-1&&j-1>=1) - { themap[i][j]*=2; + A } the if(map[i+1][j]==-1&&i+1<=N) + { -map[i][j]*=2; $ $ } - - if(map[i][j+1]==-1&&j+1<=m) the { -map[i][j]*=2;Wuyi the } - } Wu } - intans=0; About for(i=1; i<=n;i++) $ for(j=1; j<=m;j++) - { - if(map[i][j]!=-1) -ans+=Map[i][j]; A } + theprintf"%d\n", ans); - $ } the return 0; the}
Source2014 multi-university Training Contest 6