题目链接: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
2014 Multi-University Training Contest 6
Recommend
hujie   |   We have carefully selected several similar problems for you:  4929 4928 4926 4924 4923 

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

转载于:https://www.cnblogs.com/wzzkaifa/p/6901870.html

hdu 4925 Apple Tree--2014 Multi-University Training Contest 6相关推荐

  1. 【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 ...

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

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

  3. HDU 6058 - Kanade's sum | 2017 Multi-University Training Contest 3

    /* HDU 6058 - Kanade's sum [ 思维,链表 ] | 2017 Multi-University Training Contest 3 题意:给出排列 a[N],求所有区间的第 ...

  4. 9行代码AC——HDU 6857 -Clockwise or Counterclockwise(2020 Multi-University Training Contest 8)(判断三点顺序)

    励志用尽量少的代码做高效表达 Problem Description It is preferrable to read the pdf statment. After some basic geom ...

  5. HDU 6386 Age of Moyu 2018 Multi-University Training Contest 7(最短路径dijkstra)

    Age of Moyu 题意:第一行给出n,m,接下来有m条路,每一行给出 a b c ,从a到b 是c掌控. 若下一条路与上一条路不属于一个c,需要缴费1. 输出从1到N的最小花费,不通则输出-1 ...

  6. 2018 Multi-University Training Contest 3 Problem F. Grab The Tree 【YY+BFS】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6324 Problem F. Grab The Tree Time Limit: 2000/1000 MS ...

  7. HDU 6638 [2019 Multi-University Training Contest 6]

    Snowy Smile Problem Description There are n pirate chests buried in Byteland, labeled by 1,2,-,n. Th ...

  8. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

  9. HDU 6051 - If the starlight never fade | 2017 Multi-University Training Contest 2

    /* HDU 6051 - If the starlight never fade [ 原根,欧拉函数 ] | 2017 Multi-University Training Contest 2 题意: ...

最新文章

  1. 小猿圈web前端之jQuery抽奖系统
  2. 混合云存储开启企业上云新路径--阿里云混合云备份容灾方案发布
  3. 时间立即同步命令_Redis复制:主从同步
  4. 网易哲学气质H5看似眼熟,为什么大家还是忍不住转发?
  5. SQL2012 附加数据库提示5120错误解决方法
  6. C++第9周(春)项目5 - 一元一次方程类
  7. disk磁盘管理与Linux驱动编写
  8. 进程创建函数fork
  9. MODIS、VIIRS数据下载教程
  10. 一个一键修改IP设置的BAT脚本
  11. 网络安全渗透高级工具(黑客工具软件大全100套)
  12. 名人论数学——数学的本质
  13. 如何通过网页获取该网站的js框架
  14. 颠覆虚拟机的神器——WSL来了
  15. 同花顺模拟炒股软件 v8.40.29 官方版
  16. Javaweb后端技术(下)02-Mybatis
  17. openLayers6系列理论基础——Layer数据源source篇
  18. 表单ajax提交插件,详解javascript表单的Ajax提交插件的使用
  19. 谢文东的一些话,很有道理
  20. Putty的安装和使用

热门文章

  1. 如何降低90%Java垃圾回收时间?以阿里HBase的GC优化实践为例
  2. 多数人的懵逼少数人的极乐——极乐迪斯科设计反推
  3. Unity 分离贴图 alpha 通道实践
  4. 详解计算机内部存储数据的形式 二进制数
  5. RunTime类,后台快速打开浏览器
  6. RedHat5.5_X64 Linux安装oracle 11.2.0.3 报错
  7. Linux下rm -rf 后恢复文件
  8. vi / vim 字符替换详解
  9. vSphere 计算vMotion的迁移原理
  10. windows当代理服务器-CCProx的使用