题意:给出n*n的二维矩阵,和k,老鼠每次最多走k步,问老鼠从起点(0,0)出发,能够得到的最大的数(即为将每走过一点的数都加起来的和最大)是多少

和上一题滑雪一样,搜索的方向再加一个循环

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std; typedef long long LL;
int a[][],d[][],n,k;
int dir[][]={,,-,,,,,-}; int dfs(int x,int y){
if(d[x][y]) return d[x][y];//如果已经搜过这一点,则直接返回,不用再重复计算
int ans=;
for(int j=;j<=k;j++){
for(int i=;i<;i++){ //四个 方向搜
int nx=x+dir[i][]*j;
int ny=y+dir[i][]*j;
if(nx<||nx>=n||ny<||ny>=n) continue;//越界
if(a[x][y]<a[nx][ny])
ans=max(ans,dfs(nx,ny));
}
} return d[x][y]=ans+a[x][y];
} int main()
{
while(scanf("%d %d",&n,&k)!=EOF&&n!=-&&k!=-){
for(int i=;i<n;i++)
for(int j=;j<n;j++) cin>>a[i][j]; memset(d,,sizeof(d)); printf("%d\n",dfs(,));
}
return ;
}

HDU 1078 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. HDU 1078 FatMouse and Cheese 记忆化搜索DP

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

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

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

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

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

  5. !HDU 1078 FatMouse and Cheese-dp-(记忆化搜索)

    题意:有一个n*n的格子.每一个格子里有不同数量的食物,老鼠从(0,0)開始走.每次下一步仅仅能走到比当前格子食物多的格子.有水平和垂直四个方向,每一步最多走k格,求老鼠能吃到的最多的食物. 分析: ...

  6. hdu 1078 FatMouse and Cheese 记忆化dp

    只能横向或竖向走...一次横着竖着最多k步...不能转弯的.... 为毛我的500+ms才跑出来... #include<cstdio> #include<iostream> ...

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

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

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

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

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

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

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

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

随机推荐

  1. IntelliJ IDEA 调试小记

    一.IntelliJ IDEA 调试没有F6 Eclipse调试有F6,意为下一步,递增F8.可IntelliJ IDEA 调试没有这个. 二.图解 Step Over (F8): 下一步 (相当于E ...

  2. git/github在windows上使用

    问题描述:     git在Windows上的使用 问题解决:     (1)下载安装git http://msysgit.github.io/ 到该网址中下载msgit软件 注:     安装msg ...

  3. 【BZOJ】【1833】【ZJOI2010】count 数字计数

    数位DP Orz iwtwiioi 学习了一下用记忆化搜索来捉题的新姿势……但没学会TAT,再挖个坑(妈蛋难道对我来说数位DP就是个神坑吗……sigh) //BZOJ 1833 #include< ...

  4. Deep Learning and Shallow Learning

    Deep Learning and Shallow Learning 由于 Deep Learning 现在如火如荼的势头,在各种领域逐渐占据 state-of-the-art 的地位,上个学期在一门 ...

  5. android.os.DeadObjectException memory near r0: 异常处理 Consumer closed input channel or an error occurred. events=0x9

    原地址:http://www.cnblogs.com/wanqieddy/p/3495338.html android.os.DeadObjectException memory near r0: 异 ...

  6. SQLite 学习流水账笔记

    1.SQLite随机取n行数据,可加自己的条件 SELECT * FROM TableName WHERE key ? ORDER BY RANDOM() LIMIT ,Num; 2.sql语句中查询 ...

  7. 关于DotNetBar中DataGridViewX 自动全屏 Anchor属性无效问题

    由于在DataGridViewX 中使用了控件DataGridViewCheckBoxXColumn会导致 Anchor属性无效问题化,具体原因未知,建议改换为系统自带的DataGridViewChe ...

  8. POJ1248 Safecracker

    第一次写DFS的程序,虽然是个水题.1. 学了memset2. 可以存下来A-Z的各个次方的结果3. 可以排序优化4. 我用了t[0]==0来判断是否有解,也可设个flag5. 用了递归,也可用五层循 ...

  9. python 利用imap接收邮件,并保存附件

    def SaveAttachImap():# login the imap server ,retrive the  new mails ,and download the attachments. ...

  10. Unigui有用的网址

    http://www.cnblogs.com/ChinaEHR/tag/Delphi/