HDU-1078
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.
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.
1 2 5
10 11 6
12 12 7
-1 -1
思路:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int n,k;
int map[][];
int dp[][];
int t[][]={,,-,,,-,,};
int max(int a,int b) {
return a>b?a:b;
} int dfs(int x,int y)
{
int maxn = ;
int ans;
if(dp[x][y] != -) return dp[x][y];
else {
for(int i = ;i <= k;i++)
for(int j = ;j < ;j++)
{
int new_x = x+t[j][]*i;
int new_y = y+t[j][]*i;
if(new_x>=&&new_x<n&&new_y>=&&new_y<n&&map[new_x][new_y]>map[x][y])
{
ans = dfs(new_x,new_y);
maxn = max(ans,maxn);
}
}
return dp[x][y] = maxn+map[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",&map[i][j]);
memset(dp,-,sizeof(dp));
printf("%d\n",dfs(,));
}
return ;
}
HDU-1078的更多相关文章
- HDU 1078 FatMouse and Cheese(记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU 1078 FatMouse and Cheese ( DP, DFS)
HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...
- HDU 1078 FatMouse and Cheese (记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 老鼠初始时在n*n的矩阵的(0 , 0)位置,每次可以向垂直或水平的一个方向移动1到k格,每次移 ...
- hdu 1078(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 //dp[i][j]表示从点i,j处开始能获得的最多cheese #include <io ...
- (记忆化搜索) FatMouse and Cheese(hdu 1078)
题目大意: 给n*n地图,老鼠初始位置在(0,0),它每次行走要么横着走要么竖着走,每次最多可以走出k个单位长度,且落脚点的权值必须比上一个落脚点的权值大,求最终可以获得的最大权值 (题目很容 ...
- 随手练——HDU 1078 FatMouse and Cheese(记忆化搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意: 一张n*n的格子表格,每个格子里有个数,每次能够水平或竖直走k个格子,允许上下左右走,每次走的格子 ...
- hdu 1078 FatMouse and Cheese【dp】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意:每次仅仅能走 横着或竖着的 1~k 个格子.求最多能吃到的奶酪. 代码: #include ...
- hdu 1078 FatMouse and Cheese(简单记忆化搜索)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意:给出n*n的格子,每个各自里面有些食物,问一只老鼠每次走最多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
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
随机推荐
- apache SetEnv 设置
php的服务器预定义变量 $_SERVER 可以通过apache的mod_env模块来添加我们所需要的内容 来段官网介绍 Description: Modifies the environment w ...
- Hadoop HA的搭建
1.首先添加hosts文件 vim /etc/hosts 192.168.0.1 MSJTVL-DSJC-H01 192.168.0.2 MSJTVL-DSJC-H03 192.168.0.3 MSJ ...
- lab3
lamp: 在阿里云linux(Ubuntu)上安装Apache mysql php : apt-get install mysql_server mysql_client php5 php_mysq ...
- 读书笔记--用Python写网络爬虫01--网络爬虫简介
Wiki - Web crawler 百度百科 - 网络爬虫 1.1 网络爬虫何时使用 用于快速自动地获取网络信息,避免重复性的手工操作. 1.2 网络爬虫是否合法 网络爬虫目前人处于早期的蛮荒阶段, ...
- nyoj 36
//这一题是 nyoj 36 是一道求最长公共子序列的题,也是用dp做出来的 核心代码也就是一句,题目大概思路是先找到两组字符串里面相同的字母 在二维数组里面更新每次比较过后dp的值,空想很难理解 ...
- css3 3D变换和动画
3D变换和动画 建立3D空间,transform-style: preserve-3d perspective: 100px; 景深 perspective-origin:center center ...
- mongodb权威指南读书笔记
一个服务器能不能运行多个不同端口的mongo实例? 如果两个对象不相等,hashcode一定不相等:如果两个对象相等,hashcode相等或者不相等? 修改器速度42页 update({},{&quo ...
- 如何在CentOS 7上修改主机名
如何在CentOS 7上修改主机名 在CentOS中,有三种定义的主机名:静态的(static),瞬态的(transient),和灵活的(pretty).“静态”主机名也称为内核主机名,是系统在启动时 ...
- Windows系统创建硬链接文件
源文件夹:E:\深海 创建新硬链接文件夹:D:\微云同步盘\719179409\4-工作资料\深海 打开命令提示符(管理员) 敲入以下命令: 创建成功后,进入目录 D:\微云同步盘\71917 ...
- IOS开发,如何用最新的Itunes给手机装ipa文件
搜了半天,发现网上的很多教“使用Itunes给手机装ipa文件”文字都好几年了,现在的Itunes跟过去几年的功能和界面都有很大改变,话不多说直接两句话讲明白,希望帮到需要的人. 使用Itunes给手 ...