zoj 1107 FatMouse and Cheese(记忆化搜索)
题目链接:点击链接
题目大意:老鼠从(0,0)出发,每次在同一个方向上最多前进k步,且每次到达的位置上的数字都要比上一个位置上的数字大,求老鼠经过的位置上的数字的和的最大值
- #include<stdio.h>
- #include<string.h>
- #define max(a,b) a>b?a:b
- int n;
- int k;//前进的步数
- int map[105][105];
- int ans[105][105];//记忆化搜索,保存中间搜索结果
- int search(int x,int y)
- {
- int dx,dy;//要去的下一个位置
- int i,maxx = 0;
- if(ans[x][y] != -1) return ans[x][y];//已经搜索过,直接返回结果
- for(i = 1 ; i <= k ; i ++)//向前走的步数
- {
- dx = x - i;//向上
- if(dx >= 0 && dx < n && map[dx][y] > map[x][y])
- {
- ans[dx][y] = search(dx,y);
- maxx = max(maxx,ans[dx][y]);
- }
- dx = x + i;//向下
- if(dx >= 0 && dx < n && map[dx][y] > map[x][y])
- {
- ans[dx][y] = search(dx,y);
- maxx = max(maxx,ans[dx][y]);
- }
- dy = y - i;//向左
- if(dy >= 0 && dy < n && map[x][dy] > map[x][y])
- {
- ans[x][dy] = search(x,dy);
- maxx = max(maxx,ans[x][dy]);
- }
- dy = y + i;//向右
- if(dy >= 0 && dy < n && map[x][dy] > map[x][y])
- {
- ans[x][dy] = search(x,dy);
- maxx = max(maxx,ans[x][dy]);
- }
- }
- return maxx + map[x][y];
- }
- int main()
- {
- int i,j;
- while(scanf("%d%d",&n,&k) && (n != -1 && k != -1))
- {
- for(i = 0 ; i < n ; i ++)
- for(j = 0 ; j < n ; j ++)
- scanf("%d",&map[i][j]);
- memset(ans,-1,sizeof(ans));
- printf("%d\n",search(0,0));
- }
- return 0;
- }
zoj 1107 FatMouse and Cheese(记忆化搜索)的更多相关文章
- HDU - 1078 FatMouse and Cheese (记忆化搜索)
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...
- P - FatMouse and Cheese 记忆化搜索
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...
- hdu1078 FatMouse and Cheese(记忆化搜索)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1078" target="_blank">http://acm. ...
- HDU 1078 FatMouse and Cheese 记忆化搜索DP
直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记 ...
- hdu1078 FatMouse and Cheese —— 记忆化搜索
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 代码1: #include<stdio.h>//hdu 1078 记忆化搜索 #in ...
- [HDOJ1078]FatMouse and Cheese(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意:给出n, k,然后给出n*n的地图,(下标0~n-1),有一只老鼠从(0,0)处出发,只能 ...
- HDU 1078 FatMouse and Cheese (记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 老鼠初始时在n*n的矩阵的(0 , 0)位置,每次可以向垂直或水平的一个方向移动1到k格,每次移 ...
- HDU 1078 FatMouse and Cheese (记忆化搜索+dp)
详见代码 #include <iostream> #include <cstdio> #include <cstdlib> #include <memory. ...
- HDU ACM 1078 FatMouse and Cheese 记忆化+DFS
题意:FatMouse在一个N*N方格上找吃的,每一个点(x,y)有一些吃的,FatMouse从(0,0)的出发去找吃的.每次最多走k步,他走过的位置能够吃掉吃的.保证吃的数量在0-100.规定他仅仅 ...
随机推荐
- redis(三)redis+Keepalived主从热备秒级切换
一 简介 安装使用centos 5.10 Master 192.168.235.135 Slave 192.168.235.152 Vip 192.168.235.200 编译环境 yum -y in ...
- Google Map Android api V2 中使用MapView遇到CameraUpdateFactory is not initialized!的解决办法
先说一下 Map V2 API Key 的问题吧: 在打包APP时需要自己生成一个XXX.keystore 用这个密室库生成的SHA1去申请的key 作为AndroidManifest.xml 中的K ...
- debian支持ll命令
debian支持ll命令 $ ll -bash: ll: command not found 没有ll这个命令.尽管也知道ll事实上 是ls -l 这个命令的别名,可是总感觉不是非常习惯.由于之前一直 ...
- Adobe Acrobat Ⅺ Pro安装激活
1.注意一定要断网安装,如果你有防火墙拦截亦可(注意:系统自带那防火墙不行). 2.将AcrobatPro_11_Web_WWMUI.exe解压到一个目录下,找到目录下的setup.exe安装,安装时 ...
- TimeUnit
转http://blog.csdn.net/hudashi/article/details/6936604 public enum TimeUnitextends Enum<TimeUnit&g ...
- Swift - 异步加载各网站的favicon图标,并在单元格中显示
下面是一个简单的应用,表格视图的各个单元格自动异步加载各个网站的favicon图标,并显示出来. 主要是复习下如何自定义单元格,单元格中图片的异步加载,以及didSet的用法. 效果图如下: 操作步骤 ...
- 【j2ee】div浮动层拖拽
背景:近期项目中需要实现弹出浮层增加数据,并且浮动层可以拖拽 解决步骤:1.浮动层实现 2.拖拽实现 多方查资料,基本实现功能,现做demo,便于以后使用 先上图片大体展示实现效果: 再上代码,展示 ...
- PHP - 自定义函数
第7章 自定义函数 学习要点: 1.标准函数 2.自定义函数 3.文件包含 4.魔法常量 一般来讲,冗余的代码都是不好的.一而再,再而三地重写代码不仅浪费时间,从布局结构角度看也显得粗制滥造.与所有优 ...
- Opera浏览器测试移动端网站和模拟手机浏览器的方法
链接地址:http://www.neirong.org/post-256.html?utm_source=tuicool Chrome浏览器请看:Chrome浏览器测试移动端网站和模拟手机浏览器的方法 ...
- mac 压缩png图片资源 pngcrush命令
iOS应用是,xcode会对PNG文件进行优化,这样图片预览就无法显示.那么如何查看这些经过优化的文件呢? 优化的动作是由pngcrush 工具完成的,你可以再xcode中找到.pngcrush 支持 ...