Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4925
Problem Solving report: give you n*m land, now there are two operations on each piece of land, up to two operations on each land, the first is the operation of apple trees, the second is the fertilization operation, the Apple tree operation can make the block land
Grow an apple, fertilization operation can make the land adjacent to the land of the apple yield twice times the original, ask the maximum number of apples can be obtained?
For example, a 4*4 land, with 1 means the first operation on the land, 0 means that the second operation on the land, you can get the most of the operation of Apple as follows:
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0
That is, for row i, Column J, if (i + j) is odd, plant a tree, and the rest of the land is fertilized.
Pay attention to the 1 * 1 of the land to be awarded.
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5 using namespacestd;6 Const intMAXN = -+5;7 intMAP[MAXN][MAXN];8 int_x[4] = {-1,0,1,0};9 int_y[4] = {0,1,0,-1};Ten intMain () One { A intt,n,m; -scanf"%d",&T); - while(t--) the { -scanf"%d%d",&n,&m); - if(n = =1&& m = =1) - { +printf"1\n"); - Continue; + } Amemset (Map,0,sizeof(map)); at for(inti =1; I <= n;++i) - for(intj =1; J <= m;++j) - if((i + j) &1) -MAP[I][J] =1; - for(inti =1; I <= n;++i) - for(intj =1; J <= m;++j) in if(!Map[i][j]) - for(intK =0; k <4;++k) to { + intx = i +_x[k]; - inty = j +_y[k]; the if(x >=1&& x <= n && y >=1&& y <=m) *Map[x][y] *=2; $ }Panax Notoginseng intAns =0; - for(inti =1; I <= n;++i) the for(intj =1; J <= m;++j) +Ans + =Map[i][j]; Aprintf"%d\n", ans); the } + return 0; -}View Code