FatMouse and Cheese HDU - 1078 dp
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,k;
int dir[][]={{-,},{,},{,-},{,}};
int dp[][],mp[][];
bool check(int x,int y)
{
if(x<||x>n||y<||y>n)
return false;
else
return true;
}
int dfs(int x,int y)
{
int ans=;
if(!dp[x][y])
{
for(int j=;j<=k;j++)
{
for(int i=;i<;i++)
{
int xx=x+dir[i][]*j;
int yy=y+dir[i][]*j;
if(check(xx,yy)&&mp[xx][yy]>mp[x][y])
ans=max(ans,dfs(xx,yy));
else
continue;
}
}
dp[x][y]=ans+mp[x][y];
}
return dp[x][y];
}
int main()
{
while(scanf("%d%d",&n,&k))
{
if(n==-&&k==-)
break;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
scanf("%d",&mp[i][j]);
//初始化
memset(dp,,sizeof(dp));
printf("%d\n",dfs(,));
}
return ;
}
FatMouse and Cheese HDU - 1078 dp的更多相关文章
- HDU1078 FatMouse and Cheese(DFS+DP) 2016-07-24 14:05 70人阅读 评论(0) 收藏
FatMouse and Cheese Problem Description FatMouse has stored some cheese in a city. The city can be c ...
- hdu 1078 FatMouse and Cheese 记忆化dp
只能横向或竖向走...一次横着竖着最多k步...不能转弯的.... 为毛我的500+ms才跑出来... #include<cstdio> #include<iostream> ...
- ZOJ 1108 FatMouse's Speed (HDU 1160) DP
传送门: ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=108 HDU :http://acm.hdu.edu.cn/s ...
- HDU 1078 FatMouse and Cheese ( DP, DFS)
HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...
- HDU 1078 FatMouse and Cheese(记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- (记忆化搜索) FatMouse and Cheese(hdu 1078)
题目大意: 给n*n地图,老鼠初始位置在(0,0),它每次行走要么横着走要么竖着走,每次最多可以走出k个单位长度,且落脚点的权值必须比上一个落脚点的权值大,求最终可以获得的最大权值 (题目很容 ...
- 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(记忆化+dfs)
FatMouse and Cheese FatMouse has stored some cheese in a city. The city can be considered as a squar ...
- kuangbin专题十二 HDU1078 FatMouse and Cheese )(dp + dfs 记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
随机推荐
- Ubuntu18.04-Java8安装
添加ppa sudo add-apt-repository ppa:webupd8team/java sudo apt-get update 安装oracle-java-installer sudo ...
- npm/gulp/nodejs
npm淘宝镜像:https://npm.taobao.org/ vscode先安装npm淘宝镜像 再安装gulp:https://www.cnblogs.com/xiaoleiel/p/1116056 ...
- redis 5.0.7 源码阅读——整数集合intset
redis中整数集合intset相关的文件为:intset.h与intset.c intset的所有操作与操作一个排序整形数组 int a[N]类似,只是根据类型做了内存上的优化. 一.数据结构 ty ...
- 如何利用dokcer提交我的比赛代码
运气很好进入了天池的一个复赛,但是复赛评测时需要提交docker镜像,捣鼓了一个晚上,终于搞清了整套的流程.由于晚上已经下定决心要早点睡觉,害怕明早就会忘记的我还是先把步骤记录下来. 1. 安装doc ...
- clr via c# 接口
1,常用接口及其定义 public interface IDisposable{ void Dispose(); } public interface IEnumerable}{ IEnumerato ...
- C# 通过反射检查属性是否包含特定字符串
public static bool StringFilter(this object model,string filterStr) { if (string.IsNullOrEmpty(filte ...
- PHP0013:PHP操作文件案例 遍历phpdamin目录
- HTML指定页面编码
HTML指定页面编码 <meta charset="UTF-8" />
- Android中饼状图的绘制
https://blog.csdn.net/cen_yuan/article/details/52204281
- MySQL基础篇(02):从五个维度出发,审视表结构设计
本文源码:GitHub·点这里 || GitEE·点这里 一.数据场景 1.表结构简介 任何工具类的东西都是为了解决某个场景下的问题,比如Redis缓存系统热点数据,ClickHouse解决海量数据的 ...