FatMouse and Cheese 【HDU - 1078 】

hdu 1078 fatmouse and cheese 记忆化搜索 FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2394 Accepted Submission(s): 913 Problem Description FatMouse has stor 阅读详情

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的方阵中,从最左上角,每次横向或纵向走k步,每走一步都要求下一步的数字比上一步的数字更大,从起点开始走到一处求和求到一处,求出最大的和。

代码:

#include<stdio.h>
#include<iostream>
using namespace std;

int n,k;
int e[101][101],dp[101][101];
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};

int dfs(int x,int y)
{
	if(dp[x][y]) 
	   return dp[x][y];
	   
	int ans=0;
	for(int i=0;i<4;i++)
	{
		for(int j=1;j<=k;j++)
		{
			int r,c;
			r=x+j*dx[i];
			c=y+j*dy[i];
			if(r>=0 && r<n && c>=0 && c<n && e[r][c]>e[x][y])
			{
				int t=dfs(r,c);
				if(ans<t) 
				   ans=t;
			}
		}
	}
	dp[x][y]=ans+e[x][y];
	return dp[x][y];
}

int main()
{
	while(cin >> n >> k)
	{
		if(n==-1 && k==-1)
		     break;

		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
			{
				cin >> e[i][j];
				dp[i][j]=0;
			}
		dfs(0,0);
		cout << dp[0][0] <<endl;
	}
	return 0;
}

 

Cloudflare SaaS 优选IP实战:提升大陆访问速度的配置指南 本文详细介绍了如何通过Cloudflare SaaS优选IP提升中国大陆用户访问速度的配置指南。从基础环境准备到IP筛选方法,再到完整配置流程和效果验证,帮助用户突破免费套餐限制,精准优化网络线路,特别适合跨境电商和面向中国大陆用户的网站优化。 阅读详情

相关推荐

SPSS线性混合模型实战:手把手复现一篇老年认知研究的统计结果(含代码)

本文详细介绍了如何使用SPSS线性混合效应模型复现老年认知研究的统计结果,涵盖数据准备、模型构建、结果解读及可视化全流程。特别针对重复测量数据分析,提供了SPSS菜单操作与语法编写的实用技巧,帮助研究者高效处理复杂数据并验证模型假设。

weixin_42562079的博客 516

HDU---1078---FatMouse and Cheese---记忆化DFS

题目描述: Fatmouse在一个城市储存了一些奶酪。该市可以被认为是尺寸N的方形网格:每个网格位置标记(p,q),其中0 <= p <n和0 <= q <n。在每个网格位置,Fatmouse在一个洞中有0到100块奶酪。现在他会享受他最喜欢的食物。 Fatmouse始于站在位置(0,0)。他吃了他站立的奶酪,然后水平或垂直地运行到另一个位置。问题是,有一只名叫顶级杀手的超级猫坐在他的洞附近,所以每次他都可以在最多的k个位置跑到洞穴之前被顶级杀手抓住。更糟糕的是 , 在一个地点吃奶

weixin_45102820的博客 516

Ubuntu关闭更新提醒的三层控制方法:从GUI到APT配置

Linux系统更新机制本质上是包管理器(APT)驱动的自动化运维流程,其核心原理在于分离‘元数据刷新’、‘安全补丁安装’和‘用户通知’三个职能。这种分层设计既保障了基础安全性,又为系统管理员提供了策略定制空间。技术价值体现在提升生产环境稳定性、规避未经验证的内核/驱动升级风险,并支持ROS、Blender渲染、工业控制等对时序敏感的应用场景。本文聚焦Ubuntu系统入门教程中高频需求——科学关闭软件更新提醒,覆盖Ubuntu 20.04及LTS版本的GUI设置、systemd服务禁用与APT配置修改三大实操

weixin_29698641的博客 394

FatMouse and Cheese

FatMouse and Cheese (记忆化) 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 <=...

rg_lzm的博客 549

【架构设计】DDD 到底解决了什么问题

DDD作为架构设计思想帮助微服务控制规模复杂度,那它是怎么做到的呢?第一章提出了架构的根本目是解决系统复杂度,并简要说明系统复杂度的六个来源及通用解法,为我们设计架构提供了清晰可执行的操作思路。

DreamSun的博客 1161

RPA 财务共享中心与RPA赋能

在和集团财务官交流的时候,客户经常会提到FSSC,其中有准备建立FSSC,正在建立FSSC,以及已建成FSSC正使用的,当中会有些对FSSC的疑虑和问题,所以花费些时间对FSSC进行了深入调研,从而也有幸拜读了王兴山、陈剑、梅震、钱自严等专业人士写的几本关于FSSC的书,对FSSC的前因后果有了更深入的认识,同时结合自己在FSSC的一些项目经验,故做了本次分享。 本文章主要分享财务共享中心以及R...

weixin_40244959的博客 2756

FatMouse and Cheese---老鼠和奶酪

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1107 FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labe...

嵩韵儿 624

西门子 标准程序解读---> 机器手抓取和涂胶控制程序

摘要 该程序实现机械手在OP70/OP90工位的自动化控制,核心功能包括: 流程控制:分段(Seg1-Seg11)管理抓件、涂胶、放件等动作,结合DB1050/DB1250数据块监控工位状态及变位机位置反馈。 安全机制:配置干涉区(FC124)、实时检测安全光/急停信号,防止碰撞;服务程序(FB191)支持维修位触发与安全隔离。 参数配置:通过DB块关联机器人速度、节拍(FB27)、车型编码(如空过=2)及手自动模式(DB70.DBX21.2)。 应用场景:适用于汽车焊接/装配线

工控智联驿站 1239

HDU 1078 FatMouse and Cheese 解题报告

dfs+dp(记忆化搜索)

Lur 's acm blog 1523

吹气压力传感器US6310 US6330调试

更换压力传感器, 从US6310 更换为US6330。 6310有一个准备好引脚,AD转换完成后会给MCU一个脉冲 而6330就没有这个功能,6330这个引脚是用来选择SPI还是I2C接口的。(6330没有复位引脚,内部有POR功能) 因此在实现上是有根本区别的, 其它方面使用的命令也不一样, 6310 A8 A9两条命令,一个命令模块醒来,一个命令模块休眠, 6330只有一条命令AA, 命令模块开始转换。 针对这2个模块作为2种处理方法, 1. 6310,可以设置一...

明天乌儿会歌唱 2023

【32】软考软件设计师——算法题(一):分治法与动态规划深度精讲|下午第4题常考满分攻略

本文是《软件设计师·50讲通关|从零基础到工程师职称》专栏第32篇,正式开启**模块四:应用技术(下午题)算法大题专项**,聚焦下午第4道高频必考大题核心两大算法:分治法与动态规划。全文超4000字深度拆解两大经典算法的底层核心思想、算法策略识别技巧、递归边界设计、状态转移方程推导,全覆盖代码填空高频考点、时间复杂度分析、经典题型解题套路;配套可直接默写的递归代码模板、DP状态设计范式、真题完整填空案例,彻底解决考生分不清分治与DP、递归边界写错、状态转移推不出、复杂度算不对四大核心痛点。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 636

HDU1077——Catching Fish,HDU1078——FatMouse and Cheese,HDU1079——Calendar Game(深度优先)

【代码】HDU1077——Catching Fish,HDU1078——FatMouse and Cheese,HDU1079——Calendar Game(深度优先)

u014114223的博客 1883

UG NX二次开发基础篇-外部模式与DLL内部模式(二 DLL内部模式)

通常情况下,我们希望我们的外挂,在UG启动的时候,就自动加载我们的外挂,并以菜单和工具条的方式,显示在UG上面。当然,这也是市面上所有外挂的操作,因为您不可能要求你的用户,以手工加载的方式,去调用你的外挂吧。在上一篇中,有粉丝留言说,启动 bat 文件,启动EXE外挂,会提示无法找到DLL的错误,这是因为UG的环境变量设置有问题,这里,我们把BAT文件作一个修改,直接改为实际目录。EXE外部模式,还有很多部分需要添加的,如参数的传递、输出消息的显示、UG操作的消息显示,等等。Dll执行结束后,会调用。

u014657217的博客 1653

HDU - 1078 FatMouse and Cheese(记忆化搜索DP)

Problem Description 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

00后的博客 267

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

HDU-1078 FatMouse and Cheese

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 lo...

slass-mot-odet 170

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

FatMouse and Cheese HDU - 1078

题目链接: https://vjudge.net/contest/68966#problem/P 题面: 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...

mzip的博客 241

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

HDU - 1078 FatMouse and Cheese

FatMouse and Cheese 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 e

什么样的小孩 的博客 382

hdu 1078【FatMouse and Cheese】

http://acm.hdu.edu.cn/showproblem.php?pid=1078人家说是简单题,我说是神题,这个就是大大滴差距\可怜 神奇的DP+记忆化搜索 只要将各个方向递归退栈后得到的最大值用dp[x][y](这里的最优就是各个方向上的最大值加上此处的cheese)记录下来,以后如果再次搜索到这个地方时可以直接返回该处的值…… ps一句:看了别人的题解后才弄出来的…...

aoyuan4706的博客 115

HDU 1078 FatMouse and Cheese(DP)

题意  老鼠在一个小镇吃奶酪  城镇可以看成一个n*n的矩阵  其中每个格子都有一定数量的奶酪mat[i][j]   老鼠从(0,0) 开始吃   而且下个吃的格子里的奶酪必须比上个格子多   老鼠只能水平方向或者垂直方向走  而且每次走的距离不能超过k  求老鼠最多能吃多少奶酪 起点是固定的   比较容易   直接记忆化搜索 令d[i][j]表示以(i,j)为终点的最优解  那么对于所有(i

Good morning,good afternoon and good night 1139

HDU1078 FatMouse and Cheese

FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5816    Accepted Submission(s): 2373 Problem Description FatMou

ACM学习交流 429

HDU 1078-FatMouse and Cheese

FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12003    Accepted Submission(s): 5078 题目链接:点击打开链接 Problem Descr

别止的博客 232

HDU - 1078 FatMouse and Cheese

再谈记忆化搜索 题目描述: 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. A...

tran_sient的博客 295

HDU 1078 FatMouse and Cheese 递推

FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8737    Accepted Submission(s): 3665 Problem Description FatMou

canghai_wangzi的博客 274
上一篇: 整数划分 【51Nod - 1201 】
下一篇: Line 【CodeForces - 7C 】
Daisy's一乐景三
博客等级 码龄8年 2粉丝 56原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值