题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1107

http://acm.hdu.edu.cn/showproblem.php?pid=1078

1、从gird[0][0]出发,每次的方向搜索一下,每次步数搜索一下

for(i=; i<; i++)
{
for(j=; j<=k; j++)
{
int tx=x+d[i][]*j;
int ty=y+d[i][]*j;
if(tx>=&&tx<n&&ty>=&&ty<n&&grid[x][y]<grid[tx][ty])
{
int temp=memSearch(tx,ty);
if(max<temp) max=temp;
}
}
}

2、temp不断更新四个方向和每一步走多远的最优值

#include <cstdio>
#include <string.h> using namespace std; int n;///网格大小
int k;///每次最多移动的步数
int grid[][];///奶酪
int cheese[][];///记忆化搜索 ///方向
int d[][]= {{-,},{,},{,-},{,}}; ///记忆化搜
int memSearch(int x,int y)
{
int i,j;
int max=;
if(cheese[x][y]>) return cheese[x][y];
for(i=; i<; i++)
{
for(j=; j<=k; j++)
{
int tx=x+d[i][]*j;
int ty=y+d[i][]*j;
if(tx>=&&tx<n&&ty>=&&ty<n&&grid[x][y]<grid[tx][ty])
{
int temp=memSearch(tx,ty);
if(max<temp) max=temp;
}
}
}
return cheese[x][y]=max+grid[x][y];
} int main()
{
while(scanf("%d%d",&n,&k)&&n!=-&&k!=-)
{
memset(cheese,,sizeof(cheese));
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
scanf("%d",&grid[i][j]);
}
printf("%d\n",memSearch(,));
}
return ;
}

记忆化搜索,FatMouse and Cheese的更多相关文章

  1. hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)

    pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/ ...

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

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

  3. kuangbin专题十二 HDU1078 FatMouse and Cheese )(dp + dfs 记忆化搜索)

    FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

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

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

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

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

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

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1078 题目大意: 题目中的k表示横向或者竖直最多可曾经进的距离,不可以拐弯.老鼠的出发点是(1,1) ...

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

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

  8. zoj 1107 FatMouse and Cheese(记忆化搜索)

    题目链接:点击链接 题目大意:老鼠从(0,0)出发,每次在同一个方向上最多前进k步,且每次到达的位置上的数字都要比上一个位置上的数字大,求老鼠经过的位置上的数字的和的最大值 #include<s ...

  9. 随手练——HDU 1078 FatMouse and Cheese(记忆化搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意: 一张n*n的格子表格,每个格子里有个数,每次能够水平或竖直走k个格子,允许上下左右走,每次走的格子 ...

随机推荐

  1. 可编辑的el-table表格,结合input输入,upload文件上传的表格

    最近整理了一下,table表格的编辑状态,把一般表格里需要输入的类型都放进来了,实现的功能如图     这里面的input输入框没什么好说的,绑定对应的值就可以,要注意的是组件上传的upload,这个 ...

  2. oracle 错误实例分析(ORA-01078)

    01,问题描述 心血来潮想看一下启动数据库的alert log.然后把数据库给关闭了,同时也在监听日志文件    下面可谓是详细的描述了整个关机过程,也看到了无数的error [root@node1 ...

  3. DP Intro - Tree DP

    二叉苹果树 题目 有一棵苹果树,如果树枝有分叉,一定是分2叉(就是说没有只有1个儿子的结点) 这棵树共有N个结点(叶子点或者树枝分叉点),编号为1-N,树根编号一定是1. 我们用一根树枝两端连接的结点 ...

  4. xshell SSH 连接出现 outgoing encryption ,或者no matching host key algorithm found错误的解决

    首先看看xshell的使用版本,如果是xshell 4,提示的信息为:no matching host key algorithm found 如果是xshell 5,提示的是: outgoing e ...

  5. vue生命周期及使用 && 单文件组件下的生命周期

    生命周期钩子 这篇文章主要记录与生命周期相关的问题. 之前,我们讲到过生命周期,如下所示: 根据图示我们很容易理解vue的生命周期: js执行到new Vue() 后,即进入vue的beforeCre ...

  6. nodejs基础知识查缺补漏

    1. 单线程.异步I/O.对比php nodejs是单线程的,但是是异步I/O,对于高并发时,它也能够快速的处理请求,100万个请求也可以承担,但是缺点是非常的耗内存,但是我们可以加大内存, 所以能用 ...

  7. org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.

    今天报了这个异常,这是页面报的 org.springframework.dao.DataIntegrityViolationException: could not execute statement ...

  8. Windows与Unix思想

    Unix与Windows的思想 Unix中的哲学是"一切皆文件",这里的一切皆文件是一个广泛的概念,有一些特殊的设备文件,在/dev目录下 物理设备在Unix中就对应一个特殊的设备 ...

  9. windows使用bat文件定时备份文件

    遇到一个需求,需要备份Access数据库,Access生成的数据都保存在xx.mdb文件中,所以考虑使用windows任务 定时执行一个备份文件的bat文件来解决这个问题. backup.bat文件代 ...

  10. springboot如何实现微信登录,前期准备

    现在网站用微信登录真的是很多,那么具体是怎么实现的呢? 首先介绍的是微信开放平台,我们如果需要微信登录或者支付都需要在上面注册一个账号,用这个账号去为我们的网站申请的话,需要用到企业资料(家里有营业执 ...