HDU 4925 Apple Tree (Blind)

Source: Internet
Author: User

Find a pattern, plant a tree, or fertilize. Fertilize first, plant trees.

Apple TreeTime limit:2000/1000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 197 Accepted Submission (s): 135


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

#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include < iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include < stack> #include <map> #include <set> #define EPS 1e-12///#define M 1000100#define ll __int64///#define LL Long long///#define INF 0x7ffffff#define inf 0x3f3f3f3f#define PI 3.1415926535898#define Zero (x) ((Fabs (x) <eps)? 0:x)    using namespace Std;const int MAXN = 110;int Mp[maxn][maxn];int main () {int n, m;    int T;    CIN >>T;        while (t--) {scanf ("%d%d", &n, &m);        Memset (MP, 0, sizeof (MP));                    for (int i = 1; I <= N, i++) {if (i%2) {for (int j = 1; j <= m; j + = 2)            MP[I][J] = 1;            } else {for (int j = 2; j <= m; j+= 2) mp[i][j] = 1;      }} LL sum = 0;  for (int i = 1, i <= N; i++) {for (int j = 1; j <= M; j + +) {if (mp[i][j                ]) continue;                int cnt = 0;                if (i-1 >= 1) if (Mp[i-1][j]) cnt + +;                if (i+1 <= N) if (Mp[i+1][j]) cnt + +;                if (j-1 >= 1) if (mp[i][j-1]) cnt++;                if (j+1 <= m) if (mp[i][j+1]) cnt++;            Sum + = (1ll<<cnt);        }} if (sum = = 0) sum++;    cout<<sum<<endl; }}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.