2014 Multi-school Sixth 1005 | | HDU 4925 Apple Tree

Source: Internet
Author: User

Topic links

Test instructions: give you a nxm matrix, each lattice can be fertilized or an apple, grow an apple can get an apple, but if you put fertilizer on a lattice, then all the adjacent to the lattice (refers to the top and bottom of the apple tree) where the last Apple is twice times, if (I,J) there is an apple tree, ( I-1,J) and (i,j+1) fertilizer, then the Apple should be 1 twice times 2,2 twice times 4, and finally 4 apples, ask you how to arrange apples and fertilize the lattice so that the last to get the most apples.

Ideas: Draw a picture can be seen, apples and apples, fat and fat do not adjacent to the good, all the apples have fertilization, all the fertilization of the lattice are separated by apples to get the most apples.

1#include <cstdio>2#include <cstring>3#include <iostream>4 #defineLL Long Long5 6 using namespacestd;7 8 intmp[ the][ the] ;9 Ten intMain () One { A     intT, n,m; -CIN >>T; -      while(t--) the     { -CIN >> N >>m; -         if(n = =1&& m = =1) -         { +printf"1\n") ; -             Continue ; +         } AMemset (MP,0,sizeof(MP)); at          for(inti =1; I <= N; i++) -         { -             ifI2) -             { -                  for(intj =1; J <= M; J + =2) -MP[I][J] =1 ; in             } -             Else to             { +                  for(intj =2; J <= M; J + =2) -MP[I][J] =1 ; the             } *         } $LL ans =0, CNT;Panax Notoginseng          for(inti =1; I <= N; i++) -         { the              for(intj =1; J <= M; J + +) +             { ACNT =0 ; the                 if(Mp[i][j])Continue ; +                 if(I-1>=1&& mp[i-1][J]) CNT + + ; -                 if(i+1<= N && mp[i+1][J]) CNT + + ; $                 if(J-1>=1&& mp[i][j-1]) CNT + + ; $                 if(j+1<= m && mp[i][j+1]) CNT + + ; -Ans + = 1LL <<CNT; -             } the         } -printf"%i64d\n", ans);Wuyi     } 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.