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 ...
随机推荐
-
前端:圆图头像制作--border-radius : 100%
异常处理汇总-前端系列 http://www.cnblogs.com/dunitian/p/4523015.html border-radius : 100% border-radius: 6px; ...
-
简单Excel表格上传下载,POI
一.废话 Excel表格是office软件中的一员,几乎是使用次数最多的办公软件.所以在java进行企业级应用开发的时候经常会用到对应的上传下载便利办公. 目前,比较常用的实现Java导入.导出Exc ...
-
tcp/ip协议栈调用关系图
最近阅读了tcp/ip详解卷2,总结一下整个发送过程和接收过程 sendmsg \/ sendit \/ sosend(这一步将数据从用户空间拷贝到内核空间,并且会在这一步判断发送缓存空间是否充足,是 ...
-
[游戏学习24] MFC 各种绘图 字体学习
>_<:这里包含字体设置及各种绘图,只要稍微看一下代码就能理解,这里不多介绍 >_<:Hello.h #include<afxwin.h> class CMyApp ...
-
HTML之打开/另存为/打印/刷新/查看原文件等按钮的代码
■打开■ <input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开> < ...
-
POJ 1611 The Suspects(简单并查集)
( ̄▽ ̄)" #include<iostream> #include<cstdio> using namespace std; ]; void makeSet(int ...
-
Codeforces Round #367 (Div. 2) D. Vasiliy&#39;s Multiset(01字典树求最大异或值)
http://codeforces.com/contest/706/problem/D 题意:有多种操作,操作1为在字典中加入x这个数,操作2为从字典中删除x这个数,操作3为从字典中找出一个数使得与给 ...
-
endl
endl英语意思是end of line,即一行输出结束,然后输出下一行. endl与cout搭配使用,意思是输出结束.
-
Oracle11g RAC安装
双节点RAC环境,数据库 racdb 实例1:racdb1 实例2:racdb2 1.IP规划 名称 oracle-db1 oracle-db2PUBLIC I ...
-
sicily 1001. Fibonacci 2
1001. Fibonacci 2 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn-1 + F ...