http://acm.hdu.edu.cn/showproblem.php?pid=4925
Try to fertilize every apple tree, and every time you find an open space to plant an apple tree, fertilize the open space around it and no longer grow an apple tree.
#include <stdio.h> #include <iostream> #include <map> #include <set> #include <list># Include <stack> #include <vector> #include <math.h> #include <string.h> #include <queue># Include <string> #include <stdlib.h> #include <algorithm> #define LL long long#define _ll __int64# Define EPS 1e-12#define PI acos ( -1.0) #define C 240#define S 20using namespace Std;int dir[4][2] = {{ -1,0},{1,0},{0,-1},{0, 1}};int Pow[5] = {1,2,4,8,16};int main () {int test;int n,m;int a[110][110];scanf ("%d", &test), while (test--) {scanf (" %d%d ", &n,&m); Memset (A,-1,sizeof (a)); int ans = 0;for (int i = 1; I <= n; i++) {for (int j = 1; j <= M; j + +) {if ( A[I][J] = =-1) {int cnt = 0;a[i][j] = 0;for (int k = 0; k < 4; k++) {int x = I+dir[k][0];int y = j+dir[k][1];if (x >= 1 && x <= n && y >= 1 && y <= m) {if (a[x][y] = = 1 | | a[x][y] = = 1) {Cnt++;a[x][y] = 1;}}} Ans + = pow[cnt];}} printf ("%d\n", ans);} return 0;}