hdu 1078 FatMouse and Cheese
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5701 Accepted Submission(s): 2320
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.
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.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std ;
int dir[][] = {{-,},{,-},{,},{,}} ;
int n, k ;
int mat[][] ;
int dp[][] ;
void _in()
{
for(int i = ; i < n; ++i)
for(int j = ; j < n ;++j)
cin >> mat[i][j] ;
}
int getans(int i, int j)
{
int& res = dp[i][j] ;
if(res != -) return res ;
res = ;
for(int x = ; x <= k ;++x)
for(int y = ; y < ; ++y)
{
int ti = i + dir[y][] * x ;
int tj = j + dir[y][] * x ;
if(ti < || ti >= n || tj < || tj >= n) continue ;
if(mat[ti][tj] <= mat[i][j]) continue ;
res = max(res, getans(ti, tj) + mat[ti][tj]) ; }
return res ;
}
int main()
{
//freopen("in.txt","r",stdin) ;
ios::sync_with_stdio() ;
while(cin >> n >> k)
{
_in() ;
memset(dp, -, sizeof dp) ;
if(n == - && k == -) break ;
cout << getans(, ) + mat[][] << endl ;
}
return ;
}
hdu 1078 FatMouse and Cheese的更多相关文章
- HDU 1078 FatMouse and Cheese ( DP, DFS)
HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, 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(记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 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 ...
- 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 (记忆化搜索)
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的格子表格,每个格子里有个数,每次能够水平或竖直走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步所能吃到的最多的食物 一道 ...
随机推荐
- RedHat下安装MySQL
下载mysql 解压tar -xvf mysql-5.7.16-1.el6.x86_64.rpm-bundle.tar 安装MySQL-server包 rpm -ivh mysql-community ...
- Mac怎么读写NTFS格式?Mac读写NTFS格式硬盘教程
我们都知道NTFS 格式的 Windows 硬盘在Mac OS X系统下只能读取不能写入,这一问题一直困扰着很多新老Mac 用户,一般的的解决办法就是安装 NTFS 插件来让 OS X 支持 NTFS ...
- Linux Shell多命令执行
有三种: :只是顺序执行,命令之间没有任何关联,不相互影响.如 ls;date;cd /etc/ 如,创建100M的文件. && 命令之间有关系,只有前一条命令正确执行才会执行下面一 ...
- ASCII 非打印字符
项目出了问题,因为AscII非打印字符的原因,后来找了一下啊ASCII的非打印字符,总共有31个,然后我们直接全部替换成问号了. 解决方式为先找到非打印字符,这是我从网上找的非打印字符表: 进制 十六 ...
- Maven 在sts不会自动下载包的问题
1.查看maven配置setting.xml是否有设置远程仓库 2.sts是否正确配置指定了setting.xml 3.是否开启线上下载,如下图
- NYOJ之Fibonacci数
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAskAAAJwCAIAAAD0kmsHAAAgAElEQVR4nO3dvXLbOMM24O8k3PtA3E
- route netstat -rn
-n :不要使用通讯协定或主机名称,直接使用ip或port number; -ee:使用更详细的资讯来显示 [root@NB data]# route -nee Kernel IP routing t ...
- PHP中array_merge和array相加的区别分析
今天处理一个这样的问题:如何获取字符键名相同值不同的两个数组值集合,用array_merge和数组相加都不可行,让我认真比较了下PHP中array_merge和array相加的区别 首先来看看键名是s ...
- VS2013 当前不会命中断点,还没有为该文档加载任何符号
方法一: 把ie的 调试 打开,然后调试的时候 会问你 是在新示例中打开 还是 当前示例,你选择当前的就行了.还有 建议你用 ie8.0的 开发者工具 调试 非常舒服 我已经 早就不用debuger ...
- memcache(使用php操作memcache)
.概念 memcache 是一个高效的分布式的内存对象缓存系统,他可以支持把php的各种数据(数组,对象,基本数据类型)放在它管理的内存中 . 安装步骤 1.下载php_memcache.dll文件并 ...