Apple TreeTime limit:2000/1000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 251 Accepted Submission (s): 176
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
Authorbupt
Source2014 multi-university Training Contest 6
Puzzle and Code:
/* Check-in questions, constructed in the form of black and white anticipation, to get the maximum value. */#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include < Algorithm>using namespace Std;typedef __int64 ll;int m,n;bool judge (int I,int j) {if (I>=1&&I<=M&&A Mp;j>=1&&j<=n) return true; return false;} int main () {int T; cin>>t; int i,j; int ma[102][102]; while (t--) {cin>>m>>n; memset (ma,0,sizeof (MA)); for (i=1;i<=m;i++) {if (i%2==0) j=1; else j=2; for (; j<=n;j+=2) {ma[i][j]=-1; }} ll ans=0; for (int i=1;i<=m;i++) {for (int j=1;j<=n;j++) {if (ma[i][j]==0) {ma[i][j]=1; if (judge (i-1,j) &&ma[i-1][j]==-1) {ma[i][j]*=2; } if (Judge (I+1,j) &&ma[i+1][j]==-1) {ma[i][j]*=2; } if (judge (i,j-1) &&ma[i][j-1]==-1) {ma[i][j]*=2; } if (judge (i,j+1) &&ma[i][j+1]==-1) { ma[i][j]*=2; }}}} for (int. i=1;i<=m;i++) {for (int j=1;j<=n;j++) if (ma[i][j]>0) ans+=ma[i][j]; } cout<<ans<<endl; } return 0;}