HDU1078 FatMouse and Cheese(DFS+DP) 2016-07-24 14:05 70人阅读 评论(0) 收藏
FatMouse and Cheese
Problem Description
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
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
Sample Input
3 1
1 2 5
10 11 6
12 12 7
-1 -1
Sample Output
37
——————————————————————————————————————————————————————
#include <iostream>
#include <cstring>
using namespace std; int dir[4][2] = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
int mp[105][105];
int dp[105][105];
int m, k; bool cheak(int i, int j)
{
if (i < 0 || i >= m || j < 0 || j >= m)
return 0;
else
return 1;
} int dfs(int x, int y)
{
if (dp[x][y] > 0)
return dp[x][y];
int mx = 0;
int xx, yy;
for (int i = 0; i < 4;i++)
for (int j = 1; j <= k; j++)
{
xx = x + dir[i][0] * j;
yy = y + dir[i][1] * j;
if (cheak(xx, yy) && mp[xx][yy]>mp[x][y])
{
int t = dfs(xx, yy);
if (t>mx)
mx = t;
}
}
dp[x][y] = mp[x][y] + mx;
return dp[x][y];
} int main()
{
while (scanf("%d%d", &m, &k) && (m != -1 || k != -1))
{
for (int i = 0; i < m;i++)
for (int j = 0; j < m; j++)
{
scanf("%d", &mp[i][j]);
}
memset(dp, 0, sizeof(dp));
int ans=dfs(0, 0);
printf("%d\n", ans); } return 0; }
HDU1078 FatMouse and Cheese(DFS+DP) 2016-07-24 14:05 70人阅读 评论(0) 收藏的更多相关文章
- A Knight's Journey 分类: dfs 2015-05-03 14:51 23人阅读 评论(0) 收藏
A Knight’s Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34085 Accepted: 11621 ...
- Hdu1016 Prime Ring Problem(DFS) 2016-05-06 14:27 329人阅读 评论(0) 收藏
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU1426 Sudoku Killer(DFS暴力) 2016-07-24 14:56 65人阅读 评论(0) 收藏
Sudoku Killer Problem Description 自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会 ...
- HDU1258 Sum It Up(DFS) 2016-07-24 14:32 57人阅读 评论(0) 收藏
Sum It Up Problem Description Given a specified total t and a list of n integers, find all distinct ...
- leetcode N-Queens/N-Queens II, backtracking, hdu 2553 count N-Queens, dfs 分类: leetcode hdoj 2015-07-09 02:07 102人阅读 评论(0) 收藏
for the backtracking part, thanks to the video of stanford cs106b lecture 10 by Julie Zelenski for t ...
- Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1231, dp ,maximum consecutive sum of integers, find the boundaries, possibly all negative, C++ 分类: hdoj 2015-07-12 03:24 87人阅读 评论(0) 收藏
the algorithm of three version below is essentially the same, namely, Kadane's algorithm, which is o ...
- A Knight's Journey 分类: POJ 搜索 2015-08-08 07:32 2人阅读 评论(0) 收藏
A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35564 Accepted: 12119 ...
- HDU1506(单调栈或者DP) 分类: 数据结构 2015-07-07 23:23 2人阅读 评论(0) 收藏
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
随机推荐
- Haskell语言学习笔记(31)ListT
Control.Monad.Trans.List 标准库中的 ListT 的实现由于有 bug,已经被废弃. list-t 模块 这里使用 list-t 模块中的 ListT. list-t 模块需要 ...
- (3)shiro自定义realm
上面一章说到shiro的认证和授权最底层就是调用realm的getAuthorizationInfo(获取用户的角色和资源)和getAuthenticationInfo(校验账号密码是否正确)两个方法 ...
- airway之workflow
1)airway简介 在该workflow中,所用的数据集来自RNA-seq,气道平滑肌细胞(airway smooth muscle cells )用氟美松(糖皮质激素,抗炎药)处理.例如,哮喘患 ...
- R语言做条形图时候,离散变量和连续型变量的区别
1)条形图 条形图或许是最常用图形,常用来展示分类(different categories on the x-axis)和数值(numeric values on the y-axis)之间的关系. ...
- webdriver自动化脚本
1.需求如下: 启动火狐浏览器首先打开百度,等待3秒然后打开博客首页,等待2秒然后关闭浏览器 from selenium import webdriver from time import sleep ...
- 记一次spring-session登录后失效的问题
用户登录后,可以进入页面,但ajax请求或跳转其他页面时,会被当做匿名用户,即没有登录.查看session数据库,发现多出两条session,一条为正常数据,里面有对应的用户名:另一条为异常的数据,没 ...
- 索引与like优化
未建索引 mysql> alter table modulestatus drop index imei;Query OK, 457922 rows affected (4.29 sec)Rec ...
- 微信公众平台开发之基于百度 BAE3.0 的开发环境搭建(采用 Baidu Eclipse)
3.通过 SVN 检入工程 在 bae 上的应用添加部署成功后,如图 7 点击“点击查看”按钮,会打开一个新页面,页面上会打印 “hello world” ,这是因为我们的应用包含有示 ...
- .net的内置对象
一 . 获取客户端,服务器端信息: Response.Write("客户端信息:"); Response.Write("<br>浏览器类型,版本:" ...
- MVC仓储使用join
代码: var result = from mpc in this.Context.Set<Domain.S_MENU_PURVIEWCODE>() join menu in this.C ...