题目链接:点击链接

题目大意:老鼠从(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(记忆化搜索)的更多相关文章

  1. HDU - 1078 FatMouse and Cheese (记忆化搜索)

    FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...

  2. P - FatMouse and Cheese 记忆化搜索

    FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...

  3. hdu1078 FatMouse and Cheese(记忆化搜索)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1078" target="_blank">http://acm. ...

  4. HDU 1078 FatMouse and Cheese 记忆化搜索DP

    直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记 ...

  5. hdu1078 FatMouse and Cheese —— 记忆化搜索

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 代码1: #include<stdio.h>//hdu 1078 记忆化搜索 #in ...

  6. [HDOJ1078]FatMouse and Cheese(记忆化搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意:给出n, k,然后给出n*n的地图,(下标0~n-1),有一只老鼠从(0,0)处出发,只能 ...

  7. HDU 1078 FatMouse and Cheese (记忆化搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 老鼠初始时在n*n的矩阵的(0 , 0)位置,每次可以向垂直或水平的一个方向移动1到k格,每次移 ...

  8. HDU 1078 FatMouse and Cheese (记忆化搜索+dp)

    详见代码 #include <iostream> #include <cstdio> #include <cstdlib> #include <memory. ...

  9. HDU ACM 1078 FatMouse and Cheese 记忆化+DFS

    题意:FatMouse在一个N*N方格上找吃的,每一个点(x,y)有一些吃的,FatMouse从(0,0)的出发去找吃的.每次最多走k步,他走过的位置能够吃掉吃的.保证吃的数量在0-100.规定他仅仅 ...

随机推荐

  1. android大牛高焕堂最新力作-android架构师之路

    android大牛高焕堂 个人介绍: Android专家顾问,台湾Android论坛主席,现任亚太地区Android技术大会主席,台湾Android领域框架开发联盟总架构师.发表100多篇Androi ...

  2. JavaScript和JQuery获取DIV的值

    1.设计源代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  3. A2DP和AVRCP蓝牙音频传输协议的应用解释

    A2DP全名是Advenced Audio Distribution Profile 蓝牙音频传输模型拹定.A2DP 规定了使用蓝牙非同步传输信道方式,传输高质量音乐文件数据的拹议堆栈软件和使用方法, ...

  4. test code

    <?php abstract class Mediator{ abstract public function send($message, $colleague); } abstract cl ...

  5. cocos2d-x游戏开发系列教程-坦克大战游戏之坦克和地图碰撞的检测下

    上篇我们完成了地图的信息获取和碰撞检测,这篇我们整合到程序中. 在这之前我们改造一下Tank类,使它更加模块化,共容易理解: 1.改造后的Tank类声明如下: class Tank : public ...

  6. CentOS桌面环境如何打开终端以及如何将终端加入右键

    安装完CentOS的桌面环境后,默认在桌面以及右键是没有打开终端选项的,要想打开终端,可以由以下步骤: 在左上角菜单[Applications]--->[System Tools]---> ...

  7. 微信jsSDK开发

    (学习类)2015年最新微信公众平台开发 微信JSSDK开发分享功能 链接地址:http://blog.163.com/sdolove@126/blog/static/1146378852015132 ...

  8. FastDFS的学习与使用(大量帖子)

    http://www.oschina.net/p/fastdfs http://bbs.chinaunix.net/forum-240-1.html

  9. Android 之 Fragment

    一  左侧标题列表 1.1  布局 left_fragment.xml <ListView xmlns:android="http://schemas.android.com/apk/ ...

  10. VC 无标题栏对话框移动

    操作系统:Windows 7软件环境:Visual C++ 2008 SP1本次目的:实现无框移动 所谓的无标题栏对话框,是基于对话框的工程,对话框属性Border设置为None,对话框如下所示: 为 ...