题目链接: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. Mercedes BENZ C5 SD Connect Xentry Tab Kit Technical Support

    Why MB Star Diagnostic tool is so well-received by thousands of users, its technology and quality is ...

  2. js栈内存和堆内存的区别

    首先JavaScript中的变量分为基本类型和引用类型.基本类型就是保存在栈内存中的简单数据段,而引用类型指的是那些保存在堆内存中的对象. 1.基本类型 基本类型有Undefined.Null.Boo ...

  3. Python-2.7 配置 tab 自动补全功能

    作者博文地址:http://www.cnblogs.com/liu-shuai/ 之前一直使用shell编程,习惯了shell的 tab 自动补全功能,而Python的命令行却不支持 tab 自动补全 ...

  4. (转)PEP 8——Python编码风格指南

    PEP 8——Python编码风格指南标签(空格分隔): Python PEP8 编码规范原文:https://lizhe2004.gitbooks.io/code-style-guideline-c ...

  5. (转)Linux curl命令参数详解

    Linux curl命令参数详解 命令:curl在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具.它支持文件的上传和下载,是综合传输工具, ...

  6. Yii框架 多表查询实例

    Yii框架多表查询实例:总共分为两个步骤(以下的代码我全部都写在model中):1.先在主表model中声明关联表中所需要查询的字段. public $surveyls_description; // ...

  7. 常用css搜集

    div居中显示 position: fixed; top: 130px; left:0px;right:0px;margin-left:auto;margin-right:auto;

  8. 防盗链与springboot代理模式(图片文件转发)

    在搭建自己的博客网站的时候,很有可能要引入一些外部图片,毕竟多数人最开始不是在自己的平台上写博客. 因某种需要,搬运自己以前写的博客到自己的网站时,在图片这一步可能会出现问题,无法显示.其中往往就是防 ...

  9. arcgis影像批量裁剪代码

    # -*- coding:utf-8 -*- # Name: ExtractByMask_Ex_02.py # Description: Extracts the cells of a raster ...

  10. WPF 窗体在Alt+Tab中隐藏

    问题: 近段时间由于项目上的需求,需要在WPF中使用COM组件,并且由于软件界面设计等等原因,需要将部分控件显示在COM组件之上,由于WindowsFormsHost的一些原因,导致继承在WPF中的W ...