题干:

FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q < n. At each grid location Fatmouse has hid between 0 and 100 blocks of cheese in a hole. Now he's going to enjoy his favorite food.

FatMouse begins by standing at location (0,0). He eats up the cheese where he stands and then runs either horizontally or vertically to another location. The problem is that there is a super Cat named Top Killer sitting near his hole, so each time he can run at most k locations to get into the hole before being caught by Top Killer. What is worse -- after eating up the cheese at one location, FatMouse gets fatter. So in order to gain enough energy for his next run, he has to run to a location which have more blocks of cheese than those that were at the current hole.

Given n, k, and the number of blocks of cheese at each grid location, compute the maximum amount of cheese FatMouse can eat before being unable to move.

Input

There are several test cases. Each test case consists of

a line containing two integers between 1 and 100: n and k 
n lines, each with n numbers: the first line contains the number of blocks of cheese at locations (0,0) (0,1) ... (0,n-1); the next line contains the number of blocks of cheese at locations (1,0), (1,1), ... (1,n-1), and so on. 
The input ends with a pair of -1's.

Output

For each test case output in a line the single integer giving the number of blocks of cheese collected.

Sample Input

3 1
1 2 5
10 11 6
12 12 7
-1 -1

Sample Output

37

题目大意:

有一种游戏是的玩法是这样的:
有一个n*n的格子,每个格子有一个数字。
遵循以下规则:
1. 玩家每次可以由所在格子向上下左右四个方向进行直线移动,每次移动的距离不得超过m
2. 玩家一开始在第一行第一列,并且已经获得该格子的分值
3. 玩家获得每一次移动到的格子的分值
4. 玩家下一次移动到达的格子的分值要比当前玩家所在的格子的分值要大。
5. 游戏所有数字加起来也不大,保证所有数字的和不会超过int型整数的范围
6. 玩家仅能在n*n的格子内移动,超出格子边界属于非法操作
7. 当玩家不能再次移动时,游戏结束
现在问你,玩家所能获得的最大得分是多少?

输入是n和m。

解题报告:

水题,,但是刚开始读错题,没看到只能从(1,1)点开始游戏 这个条件,所以WA了、、

AC代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;int nx[4] = {0,1,0,-1};
int ny[4] = {1,0,-1,0};
ll dp[105][105];
int a[105][105];int n,m;
bool ok(int x,int y) {if(x>=1&&x<=n&&y>=1&&y<=n) return 1;else return 0;
}
ll dfs(int x,int y) {if(dp[x][y] != -1) return dp[x][y];ll res = 0;int tx,ty;for(int k = 0; k<4; k++) {tx = x;ty = y;for(int i = 1; i<=m; i++) {tx += nx[k];ty += ny[k];if(ok(tx,ty)==0) continue;if(a[tx][ty] <= a[x][y]) continue;res = max(res,dfs(tx,ty));}}return dp[x][y]=res+a[x][y];}
int main()
{while(~scanf("%d%d",&n,&m)) {if(n==-1 && m==-1) break;memset(dp,-1,sizeof dp);ll ans = 0;for(int i = 1; i<=n; i++) {for(int j = 1; j<=n; j++) {scanf("%d",&a[i][j]);}}
//      for(int i = 1; i<=n; i++) {
//          for(int j = 1; j<=n; j++) {
//              ans = max(ans,dfs(i,j));
//          }
//      }ans = dfs(1,1);printf("%lld\n",ans);} return 0 ;} 

【HDU - 1078】FatMouse and Cheese (记忆化搜索dp)相关推荐

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

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

  2. [蓝桥杯][算法提高VIP]夺宝奇兵(记忆化搜索||DP)

    题目描述 在一座山上,有很多很多珠宝,它们散落在山底通往山顶的每条道路上,不同道路上的珠宝的数目也各不相同.下图为一张藏宝地图: 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 " ...

  3. HDU 1078 FatMouse and Cheese【记忆化搜索】

    <题目链接> 题目大意: 给你一个n*n的矩阵,每个矩阵上有相应数量的奶酪,老鼠一次最多走K步,且每次只能横着走或者竖着走,并且每一次停留位置上的奶酪数一定要多余它刚才的奶酪数,求这只老鼠 ...

  4. HDU - 1078 FatMouse and Cheese

    再谈记忆化搜索 题目描述: FatMouse has stored some cheese in a city. The city can be considered as a square grid ...

  5. HDU 1176 免费馅饼(记忆化搜索)

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  6. HDU 2452 Navy maneuvers (记忆化搜索)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2452 题意:给出一个图,n个点,m条边,保证无环,每个点有一个权值.指定一个点作为起点,Victory和G ...

  7. 【HDU - 2571】 命运(记忆化搜索)

    题干: 穿过幽谷意味着离大魔王lemon已经无限接近了!  可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个机关.要知道,不论何人,若在迷 ...

  8. 【牛客 - 301哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(高年级)】小乐乐下象棋(记忆化搜索dp,dfs)

    题干: 小乐乐一天天就知道玩,这一天又想玩象棋. 我们都知道马走日. 现在给定一个棋盘,大小是n*m,把棋盘放在第一象限,棋盘的左下角是(0,0),右上角是(n - 1, m - 1); 小乐乐想知道 ...

  9. UVA10739 String to Palindrome【记忆化搜索+DP】

    In this problem you are asked to convert a string into a palindrome with minimum number of operation ...

  10. hdu 1078 FatMouse and Cheese(记忆化搜索)

    题意:一个n*n的矩阵,每个点有若干块点心,小老鼠开始在左上角,每次最多往前走k步,且停留的点的点心数比上一次停留的点大,输出最大的i点心数 分析:停留的点数目必须比上次大,形成一个序,必定是一个DA ...

最新文章

  1. Oracle技术之实例恢复的顺序
  2. BTC.com率先发起使用开放联盟网关协议OFGP,联合iBitcome钱包携手送糖果
  3. 图书馆座位预定系统开发
  4. 【C 语言】数组与指针操作 ( 数组符号 [] 与 指针 * 符号 的 联系 与 区别 | 数组符号 [] 与 指针 * 符号 使用效果 基本等价 | 数组首地址 与 指针 本质区别 )
  5. 游戏开发--开源软件11--Firefly(python 服务端分布式框架)||pygame
  6. java map 如何根据key获得对象_ThreadLocal:Java中的影分身
  7. 大学学好高数的爆炸性意义!
  8. 【linux 001】【利用staging Driver】【001】wifi AR6000 驱动移植引发的 staging 的问题
  9. 德国高级码农可赚年薪20万,但他们不在乎钱
  10. php dir()函数的用法
  11. mac 安装php7.4
  12. 通过外挂插件向预训练语言模型中融入知识
  13. Mysql中间件代理 Atlas
  14. 儿童学计算机编程好处,十个理由告诉你孩子为什么要学习编程?
  15. 古代汉语(王力版)笔记 绪论
  16. 分享9个ps、pr免费教程网站
  17. 机器视觉学习笔记(6)——双目摄像机标定参数说明
  18. 鸟哥的Linux私房菜之Linux 的文件权限与目录管理(一)
  19. python是一门跨平台语言_python属于跨平台语言码
  20. access和tagware_NDoc 用户指南

热门文章

  1. [剑指offer]面试题第[25]题[Leedcode][JAVA][第21题][合并两个有序链表]
  2. next_permutation算法(基于交换)
  3. Codeforce Flea CodeForces - 32C 规律|思维
  4. oracle自动备份定时任务,Oracle数据库定时自动备份批处理代码(Windows)
  5. c语言笔记之数组和指针(初学者)
  6. matlab设计理想数字带通滤波器,基于matlab的数字带通滤波器课程设计报告
  7. 提高应用程序稳定的小内容
  8. Vim功能键整理(图片来自mooc)
  9. 安利一款编辑神器——Markdown
  10. html5同心圆代码,HTML5/Canvas 鼠标跟随的同心圆