HDU 4925 Apple Tree (simulated problem)

Source: Internet
Author: User

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

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.