记忆化搜索,FatMouse and Cheese
题目链接: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的更多相关文章
- hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)
pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...
- HDU - 1078 FatMouse and Cheese (记忆化搜索)
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...
- kuangbin专题十二 HDU1078 FatMouse and Cheese )(dp + dfs 记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 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. ...
- hdu1078 FatMouse and Cheese(记忆化搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1078 题目大意: 题目中的k表示横向或者竖直最多可曾经进的距离,不可以拐弯.老鼠的出发点是(1,1) ...
- HDU 1078 FatMouse and Cheese 记忆化搜索DP
直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记 ...
- zoj 1107 FatMouse and Cheese(记忆化搜索)
题目链接:点击链接 题目大意:老鼠从(0,0)出发,每次在同一个方向上最多前进k步,且每次到达的位置上的数字都要比上一个位置上的数字大,求老鼠经过的位置上的数字的和的最大值 #include<s ...
- 随手练——HDU 1078 FatMouse and Cheese(记忆化搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意: 一张n*n的格子表格,每个格子里有个数,每次能够水平或竖直走k个格子,允许上下左右走,每次走的格子 ...
随机推荐
- shell 进阶变量的指定 declare
declare 设置 -r 只读 -i 设置整形 -a 数组 让指定的函数成为一个数组 -f 函数 如果在脚本中使用declare -f, 而不加任何参数的话, 那么将会列出这个脚本之前定义的所有函数 ...
- Unity 修改windows窗口的标题
修改windows窗口的标题名称,就是修改下图的东西: 第一种: using UnityEngine; using System; using System.Runtime.InteropServic ...
- Redis启动和关闭
带配置文件启动 ./redis-server redis.conf 关闭 无密码模式 ./redis-cli -h xxx -p xxx shutdown 密码模式 ./redis-cli -h ...
- 使用Amoeba for mysql实现mysql读写分离(测试可行)
Amoeba for MySQL致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的时候充当query 路由功能,专注 分布式数据库 proxy 开发.座落与Client.DB S ...
- netstat参数
1.功能与说明 netstat 用于显示linux中各种网络相关信息.如网络链接.路由表.接口状态链接.多播成员等等. 定义:Netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TC ...
- pL/SQL 创建DBLIKN
某些时候,需要关联不同的数据库进行数据查询.操作等. 在Oracle中,关联不同的数据库进行表关联,就要用到了数据库连接(DB link). 创建DB link有两种方法:通过SQL语句创建,通过可视 ...
- ubuntu遇到了 dpkg was interrupted, you must manually run 'dpkg..的问题
dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem. E: _cache- ...
- [转]什么?你还不会写JQuery 插件
本文转自:http://www.cnblogs.com/joey0210/p/3408349.html 前言 如今做web开发,jquery 几乎是必不可少的,就连vs神器在2010版本开始将Jque ...
- node.js发邮件
在node上使用第三方类库(nodemailer)发邮件是一件很esay的事情:) app.js 以QQ邮箱为例 var nodemailer = require('nodemailer'); v ...
- attribute和property的区别
DOM元素的attribute和property很容易混倄在一起,分不清楚,两者是不同的东西,但是两者又联系紧密.很多新手朋友,也包括以前的我,经常会搞不清楚. attribute翻译成中文术语为“特 ...