码迷,mamicode.com
首页 > 移动开发 > 详细

hdu4925Apple Tree

时间:2015-08-31 23:43:56      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

//n*m的果园 , 种一棵树,收获一个果实
//在一个格子施肥 , 其旁边的果树收获的·果实翻倍
//问最多能收获多少果实
//交叉种树 , 则为最大
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 110 ;
int map[maxn][maxn] ;
int dx[4] = {0 , 1 , 0  ,-1} ;
int dy[4] = {1 , 0 , -1 , 0} ;
int main()
{
    int n , m ;
    int t ;
    scanf("%d" , &t) ;
    while(t--)
    {
        cin>>n>>m ;
        memset(map , 0 , sizeof(map)) ;
        int ans = 0  ;
        for(int i = 1;i <= n;i++)
          for(int j = 1;j <= m;j++)
          if((i+j)%2 == 0)
          {
              int sum = 0 ;
              for(int k = 0 ;k < 4;k++)
              {
                  int nx = i + dx[k] ;
                  int ny = j + dy[k] ;
                  if(nx >= 1 && nx <= n && ny >= 1 && ny <= m)
                  sum++ ;
              }
              ans += (1<<sum) ;
           }
           cout<<ans<<endl ;
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu4925Apple Tree

标签:

原文地址:http://blog.csdn.net/cq_pf/article/details/48141805

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!