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