hdu4925Apple Tree

//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 ;
    }
}

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

时间: 2024-12-23 14:37:23

hdu4925Apple Tree的相关文章

HDU4925-Apple Tree

题意:n*m网格中种苹果,每个网格要么施肥,要么种一个苹果,每个种苹果的格子,如果它的上下左右有各自有施肥的话,每有一个,苹果数量*2,求怎么种使得苹果数量最多. 思路:交叉种植,即黑白染色法可得到最优解.注意特判当n=m=1时的情况. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAX

hdu4925Apple Tree(找规律)

题目:hdu4925Apple Tree(找规律) 题目大意:给出N* M 的矩阵,然后每个格子要不种苹果,要不施肥:在(X,Y)施肥后,它上下左右的苹果树的产量会翻倍.种了苹果数,产量为1.求这样的N * M个矩阵能得到的最大的苹果数. 解题思路: 对于2 * 2的矩阵: X代表施肥 , 有数字代表种树  X 2  这样是最好的.各自上的数字代表这个格子被施肥几次.那么2 * 2的最多的苹果数 2 ^2 + 2^2 = 8; 2 X 3 * 3 : X  3 X 3  X   3 X  3  

easyui js取消选中 Tree 指定节点

取消所有选中 var rootNodes = treeObject.tree('getRoots'); for ( var i = 0; i < rootNodes.length; i++) { var node = treeObject.tree('find', rootNodes[i].id); treeObject.tree('uncheck', node.target); }

Maximum Depth of Binary Tree

这道题为简单题 题目: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 思路: 我是用递归做的,当然也可以用深搜和广搜,递归的话就是比较左右子树的深度然后返回 代码: 1 # Definition for a binary tre

538. Convert BST to Greater Tree 二叉搜索树转换为更大树

Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST. Example: Input: The root of a Binary Search Tree like thi

SPOJ375 Query on a tree

https://vjudge.net/problem/SPOJ-QTREE 题意: 一棵树,每条边有个权值 两种操作 一个修改每条边权值 一个询问两点之间这一条链的最大边权 点数<=10000 多组测试数据,case<=20 Example Input: 1 3 1 2 1 2 3 2 QUERY 1 2 CHANGE 1 3 QUERY 1 2 DONE Output: 1 3 #include<cstdio> #include<iostream> #include&

POJ 1741 Tree(树的点分治,入门题)

Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21357   Accepted: 7006 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001).Define dist(u,v)=The min distance between node u and v.Give an in

命令-tree

tree命令 tree - list contents of directories in a tree-like format. 显示目录的层级结构: tree 命令英文理解为树的意思,其功能是创建文件列表,将目录所有文件以树状的形式列出来.linux中的tree命令默认并不会安装,所以需要通过yum install tree -y来安装此命令. [SYNOPSIS] tree [options] [directory] [OPTIONS] -L level:指定要显示的层级: -d:仅列出目

[LeetCode] Find Mode in Binary Search Tree 找二分搜索数的众数

Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than or equal to the nod