HDU 1078 FatMouse and Cheese (记忆化搜索+dp)
详见代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <memory.h>
using namespace std;
const int inf=0x3f3f3f3f;
int a[][];
int dp[][];//表示到i,j的最大路径和
int dir[][]= {,,-,,,,,-};
int n,m;
int dfs(int x,int y)
{
int ans=;
if(!dp[x][y])
{
for(int i=; i<=m; i++)
{
for(int j=; j<; j++)
{
int xx=x+dir[j][]*i;
int yy=y+dir[j][]*i;
if(xx<||xx>n||yy<||yy>n)
{
continue;
}
if(a[xx][yy]>a[x][y])
{
ans=max(ans,dfs(xx,yy));
}
}
}
dp[x][y]=ans+a[x][y];
}
return dp[x][y];
}
int main()
{
// int n,m;
while(~scanf("%d%d",&n,&m),n>&&m>)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
scanf("%d",&a[i][j]);
}
}
memset(dp,,sizeof(dp));
printf("%d\n",dfs(,));
}
return ;
}
HDU 1078 FatMouse and Cheese (记忆化搜索+dp)的更多相关文章
- HDU 1078 FatMouse and Cheese 记忆化搜索DP
直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记 ...
- HDU - 1078 FatMouse and Cheese (记忆化搜索)
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...
- HDU 1078 FatMouse and Cheese (记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 老鼠初始时在n*n的矩阵的(0 , 0)位置,每次可以向垂直或水平的一个方向移动1到k格,每次移 ...
- !HDU 1078 FatMouse and Cheese-dp-(记忆化搜索)
题意:有一个n*n的格子.每一个格子里有不同数量的食物,老鼠从(0,0)開始走.每次下一步仅仅能走到比当前格子食物多的格子.有水平和垂直四个方向,每一步最多走k格,求老鼠能吃到的最多的食物. 分析: ...
- hdu 1078 FatMouse and Cheese 记忆化dp
只能横向或竖向走...一次横着竖着最多k步...不能转弯的.... 为毛我的500+ms才跑出来... #include<cstdio> #include<iostream> ...
- HDU ACM 1078 FatMouse and Cheese 记忆化+DFS
题意:FatMouse在一个N*N方格上找吃的,每一个点(x,y)有一些吃的,FatMouse从(0,0)的出发去找吃的.每次最多走k步,他走过的位置能够吃掉吃的.保证吃的数量在0-100.规定他仅仅 ...
- 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 代码1: #include<stdio.h>//hdu 1078 记忆化搜索 #in ...
- P - FatMouse and Cheese 记忆化搜索
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...
随机推荐
- (hdu)1160 FatMouse's Speed
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- _itoa_s, _i64toa_s, _ui64toa_s, _itow_s, _i64tow_s, _ui64tow_s
Converts an integer to a string. These are versions of _itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui ...
- 切换到mint了,纪念一下
- Spring in action笔记
耦合的两面性 一方面代码耦合难以测试,会出现打地鼠式的bug特性(修复一个bug,引发另一个bug) 另一方面耦合又是必须的,不同的类必须要进行适当的交互,才能实现功能. bean的四种装配方 ...
- Shell中特殊符号
http://blog.chinaunix.net/u1/53027/showart.php?id=482234 在shell中常用的特殊符号罗列如下:# ; ;; . ...
- 网站开发常用jQuery插件总结(12)固定元素插件scrolltofixed
这个插件在前段时间用过一次,当时是改一个网站.要求顶部的菜单栏随着滚动条的滚动而固定.也大体写了一下,不过在文章中也只是提了一下,文章地址:jQuery插件固定元素位置. 在这篇文章中,再进行总结一下 ...
- 使用JS实现鼠标滚轮事件
网站需要实现鼠标滚轮滚一下,页面向下滑向下一个锚点,由于前面有个一样式必须用jQuery1.3.2,而好多滚轮事件都使用了更高版本的jQuery,于是就从网上找了找 <script type=& ...
- PHP实现斐波那契数列非递归方法
斐波那契数列,又称黄金分割数列,指的是这样一个数列:0.1.1.2.3.5.8.13.21.……在数学上,斐波纳契数列以如下被以递归的方法定义:F0=0,F1=1,Fn=F(n-1)+F(n-2)(n ...
- FastCgi与PHP-fpm关系[转] 读完本文瞬间明朗了很多
刚开始对这个问题我也挺纠结的,看了<HTTP权威指南>后,感觉清晰了不少. 首先,CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式的,方便CGI程序的编写者. ...
- 定时生成bat命令
windows下,定时生成bat的名. at 14:54 cmd /c "echo net share D=d:\ > d:d.bat" ^对>转义.