FatMouse and Cheese 动态化搜索
FatMouse and Cheese
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7576 Accepted Submission(s): 3133
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.
1 2 5
10 11 6
12 12 7
-1 -1
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
int n,k;
const int maxn = ;
int maze[maxn][maxn],dp[maxn][maxn];
int dfs(int p,int q){
if(dp[p][q]) return dp[p][q];
int l,r,d,u;
int ans = ,maxx = ;
l = p - k;
r = p + k;
if(l<) l = ;
if(r>=n) r = n-;
for(int i = l; i<=r; i++){
if(maze[i][q]>maze[p][q]){
ans = dfs(i,q);
if(ans>maxx) maxx = ans;
}
}
u = q + k;
d = q - k;
if(d<) d = ;
if(u>=n) u = n-;
for(int i = d; i<=u; i++){
if(maze[p][i]>maze[p][q]){
ans = dfs(p,i);
if(ans>maxx) maxx = ans;
}
}
dp[p][q] = maxx + maze[p][q];
return dp[p][q];
}
void input(){
while(scanf("%d%d",&n,&k)!=EOF&&n != -&&k != -){
for(int i = ; i<n; i++)
for(int j = ; j<n; j++)
scanf("%d",&maze[i][j]);
memset(dp,,sizeof(dp));
printf("%d\n",dfs(,));
}
}
int main()
{
input();
return ;
}
卷珠帘
FatMouse and Cheese 动态化搜索的更多相关文章
- hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)
pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...
- kuangbin专题十二 HDU1078 FatMouse and Cheese )(dp + dfs 记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU 1078 FatMouse and Cheese(记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- (记忆化搜索) FatMouse and Cheese(hdu 1078)
题目大意: 给n*n地图,老鼠初始位置在(0,0),它每次行走要么横着走要么竖着走,每次最多可以走出k个单位长度,且落脚点的权值必须比上一个落脚点的权值大,求最终可以获得的最大权值 (题目很容 ...
- HDU1078 FatMouse and Cheese 【内存搜索】
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- FatMouse and Cheese
FatMouse and Cheese Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU1078 FatMouse and Cheese(DFS+DP) 2016-07-24 14:05 70人阅读 评论(0) 收藏
FatMouse and Cheese Problem Description FatMouse has stored some cheese in a city. The city can be c ...
- HDU 1078 FatMouse and Cheese ( DP, DFS)
HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...
- 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 ...
随机推荐
- HDU1272 小希的迷宫 并查集
参考网址:http://blog.sina.com.cn/s/blog_6827ac4a0100nyjy.html 解题思路: 由于这里出现的数字不一定连续的数字都会出现,所以设一个mark来标记数字 ...
- LD_LIBRARY_PATH vs LIBRARY_PATH
LIBRARY_PATH is used by gcc before compilation to search for directories containing libraries that n ...
- LeetCode OJ 66. Plus One
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
- EntityFramwork所有 SSDL 项目都必须以同一提供程序为目标。ProviderManifestToken“2008”不同于以前遇到的“2005”
再用spring+mvc+EF搭建框架时,出现这个问题,网上没有找到类似的问题,删除实体重建后莫名其妙的好了,2008指的是连得数据库实例是2008版本的,2005指的是2005版本,出现问题的原因是 ...
- Java学习笔记之static
1.static可以用于修饰成员变量.方法以及块,并不会改变类中成员的权限修饰,如:private修饰的成员变量,类外只能类名或非私有方法调用,而不能使用对象名调用. 2.static方法和成员变量, ...
- Spring中实现监听的方法
在未使用框架进行编程的时候,我们常常在web.xml中加上这样一段话 <listener> <listener-class>XXX</listener-class> ...
- Spring Boot 系列教程14-动态修改定时任务cron参数
动态修改定时任务cron参数 不需要重启应用就可以动态的改变Cron表达式的值 不能使用@Scheduled(cron = "${jobs.cron}")实现 DynamicSch ...
- Android中获取网络数据时的分页加载
//此实在Fragment中实现的,黄色部分为自动加载,红色部分是需要注意的和手动加载, 蓝色部分是睡眠时间,自我感觉不用写 ,还有就是手动加载时,不知道为什么进去后显示的就是最后一行,求大神 ...
- Excel 帮助类
using System; using System.Collections.Generic; using System.Data; using System.Drawing; using Syste ...
- SQL Server 索引维护sql语句
使用以下脚本查看数据库索引碎片的大小情况: 复制代码代码如下: DBCC SHOWCONTIG WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS 以 ...