题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925

Apple Tree

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Total Submission(s): 188    Accepted Submission(s): 129

Problem Description
I’ve bought an orchard and decide to plant some apple trees on it. The orchard seems like an N * M two-dimensional map. In each grid, I can either plant an apple tree to get one apple or fertilize the soil to speed up its neighbors’ production. When a grid
is fertilized, the grid itself doesn’t produce apples but the number of apples of its four neighbor trees will double (if it exists). For example, an apple tree locates on (x, y), and (x - 1, y), (x, y - 1) are fertilized while (x + 1, y), (x, y + 1) are not,
then I can get four apples from (x, y). Now, I am wondering how many apples I can get at most in the whole orchard?
 
Input
The input contains multiple test cases. The number of test cases T (T<=100) occurs in the first line of input.

For each test case, two integers N, M (1<=N, M<=100) are given in a line, which denote the size of the map.
 
Output
For each test case, you should output the maximum number of apples I can obtain.
 
Sample Input
2
2 2
3 3
 
Sample Output
8
32
 
Source
 
Recommend
 

Statistic | Submit | Discuss | Note

签道题,没啥好说的,黑白染色的方法是最优的,特判1*1的情况

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define CLR(A) memset(A,0,sizeof(A))
int A[110][110];
int main(){
int T,m,n;
cin>>T;
while(T--){
cin>>n>>m;
if(n==1 && m==1){
cout<<1<<endl;
continue;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
A[i][j]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
if(A[i][j]==1){
A[i-1][j]<<=1;
A[i+1][j]<<=1;
A[i][j-1]<<=1;
A[i][j+1]<<=1;
}
}
long long sum=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
if(A[i][j]!=1){
sum+=A[i][j];
}
}
cout<<sum<<endl;
}
return 0;
}

hdu 4925 Apple Tree--2014 Multi-University Training Contest 6的更多相关文章

  1. HDU 4925 Apple Tree(推理)

    HDU 4925 Apple Tree 题目链接 题意:给一个m*n矩阵种树,每一个位置能够选择种树或者施肥,假设种上去的位置就不能施肥,假设施肥则能让周围果树产量乘2.问最大收益 思路:推理得到肯定 ...

  2. HDU 4925 Apple Tree (瞎搞)

    找到规律,各一个种一棵树.或者施肥.先施肥,先种树一样. Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 2621 ...

  3. 2014多校第六场 1005 || HDU 4925 Apple Tree

    题目链接 题意 : 给你一块n×m的矩阵,每一个格子可以施肥或者是种苹果,种一颗苹果可以得到一个苹果,但是如果你在一个格子上施了肥,那么所有与该格子相邻(指上下左右)的有苹果树的地方最后得到的苹果是两 ...

  4. HDU 4925 Apple Tree(模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 解题报告:给你n*m的土地,现在对每一块土地有两种操作,最多只能在每块土地上进行两种操作,第一种 ...

  5. hdoj 4925 Apple tree 【最小割】

    题目:pid=4925">hdoj 4925 Apple tree 来源:2014 Multi-University Training Contest 6 题意:给出一个矩阵,然后每一 ...

  6. 【HDU 4925】BUPT 2015 newbie practice #2 div2-C-HDU 4925 Apple Tree

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/C Description I’ve bought an or ...

  7. HDU 6091 - Rikka with Match | 2017 Multi-University Training Contest 5

    思路来自 某FXXL 不过复杂度咋算的.. /* HDU 6091 - Rikka with Match [ 树形DP ] | 2017 Multi-University Training Conte ...

  8. HDU 6125 - Free from square | 2017 Multi-University Training Contest 7

    思路来自这里 - - /* HDU 6125 - Free from square [ 分组,状压,DP ] | 2017 Multi-University Training Contest 7 题意 ...

  9. HDU 6129 - Just do it | 2017 Multi-University Training Contest 7

    比赛时脑子一直想着按位卷积... 按题解的思路: /* HDU 6129 - Just do it [ 规律,组合数 ] | 2017 Multi-University Training Contes ...

随机推荐

  1. fshc模块fsch2mcu_if理解

    fshc2mcu_if中包括ahb2reg/ahb2fifo两个文件,都是协议转换文件.ahb2reg下游文件是reg files,ahb2fifo下游文件是fifo控制器.所有的配置和flag都是要 ...

  2. Linux mint xfce 19 使用记录

    创建系统快照 创建系统快照是 Linux Mint 19 的重要建议,可以使用与更新管理器捆绑的 Timeshift 应用程序轻松完成创建与恢复. 这个阶段很重要,万一出现令人遗憾的事件,比如安装破坏 ...

  3. Google JavaScript代码风格指南

    Google JavaScript代码风格指南 修正版本 2.28 Aaron Whyte Bob Jervis Dan Pupius Eric Arvidsson Fritz Schneider R ...

  4. 大数据学习——java操作hdfs环境搭建以及环境测试

    1 新建一个maven项目 打印根目录下的文件的名字 添加pom依赖 pom.xml <?xml version="1.0" encoding="UTF-8&quo ...

  5. 【网络流】codeforces C. Heidi and Library (hard)

    http://codeforces.com/contest/802/problem/C

  6. hdu 3940

    #include<stdio.h> #include<math.h> #include<string.h> double first(double vx,doubl ...

  7. WebApi下载附件文件

    WebApi下载附件文件 1. [RoutePrefix("down")] public class FilesController : ApiController { [GET( ...

  8. 【BZOJ1211】树的计数(Prufer编码)

    题意:一个有n个结点的树,设它的结点分别为v1, v2, …, vn, 已知第i个结点vi的度数为di,问满足这样的条件的不同的树有多少棵. 其中1<=n<=150,输入数据保证满足条件的 ...

  9. Linux内核设计与实现——读书笔记2:进程管理

    1.进程: (1)处于执行期的程序,但不止是代码,还包括各种程序运行时所需的资源,实际上进程是正在执行的 程序的实时结果. (2)程序的本身并不是进程,进程是处于执行期的程序及其相关资源的总称. (3 ...

  10. D. Little Artem and Dance---cf669D

    http://codeforces.com/problemset/problem/669/D 题目大意: 有n对人 男生和女生 开始时  每个人的标号是(1,2,3,...n) 女生们围成一个圈  男 ...