FatMouse and Cheese 动态化搜索

时间:2022-09-03 09:39:40

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

Problem Description
FatMouse
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.

 
Input
There are several test cases. Each test case consists of

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
For each test case output in a line the single integer giving the number of blocks of cheese collected.
 
Sample Input
3 1
1 2 5
10 11 6
12 12 7
-1 -1
 
Sample Output
37
 动态化搜索,详见代码。
 #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 动态化搜索的更多相关文章

  1. hdu 1078 FatMouse and Cheese (dfs&plus;记忆化搜索)

    pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/ ...

  2. kuangbin专题十二 HDU1078 FatMouse and Cheese )&lpar;dp &plus; dfs 记忆化搜索&rpar;

    FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  3. HDU 1078 FatMouse and Cheese(记忆化搜索)

    FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  4. (记忆化搜索) FatMouse and Cheese(hdu 1078)

    题目大意:   给n*n地图,老鼠初始位置在(0,0),它每次行走要么横着走要么竖着走,每次最多可以走出k个单位长度,且落脚点的权值必须比上一个落脚点的权值大,求最终可以获得的最大权值   (题目很容 ...

  5. HDU1078 FatMouse and Cheese 【内存搜索】

    FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  6. FatMouse and Cheese

    FatMouse and Cheese Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  7. HDU1078 FatMouse and Cheese(DFS&plus;DP) 2016-07-24 14&colon;05 70人阅读 评论&lpar;0&rpar; 收藏

    FatMouse and Cheese Problem Description FatMouse has stored some cheese in a city. The city can be c ...

  8. HDU 1078 FatMouse and Cheese &lpar; DP&comma; DFS&rpar;

    HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...

  9. HDU - 1078 FatMouse and Cheese(记忆化&plus;dfs)

    FatMouse and Cheese FatMouse has stored some cheese in a city. The city can be considered as a squar ...

随机推荐

  1. 前端:圆图头像制作--border-radius &colon; 100&percnt;

    异常处理汇总-前端系列 http://www.cnblogs.com/dunitian/p/4523015.html border-radius : 100% border-radius: 6px; ...

  2. 简单Excel表格上传下载,POI

    一.废话 Excel表格是office软件中的一员,几乎是使用次数最多的办公软件.所以在java进行企业级应用开发的时候经常会用到对应的上传下载便利办公. 目前,比较常用的实现Java导入.导出Exc ...

  3. tcp&sol;ip协议栈调用关系图

    最近阅读了tcp/ip详解卷2,总结一下整个发送过程和接收过程 sendmsg \/ sendit \/ sosend(这一步将数据从用户空间拷贝到内核空间,并且会在这一步判断发送缓存空间是否充足,是 ...

  4. &lbrack;游戏学习24&rsqb; MFC 各种绘图 字体学习

    >_<:这里包含字体设置及各种绘图,只要稍微看一下代码就能理解,这里不多介绍 >_<:Hello.h #include<afxwin.h> class CMyApp ...

  5. HTML之打开&sol;另存为&sol;打印&sol;刷新&sol;查看原文件等按钮的代码

    ■打开■ <input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开> < ...

  6. POJ 1611 The Suspects(简单并查集)

    ( ̄▽ ̄)" #include<iostream> #include<cstdio> using namespace std; ]; void makeSet(int ...

  7. Codeforces Round &num;367 &lpar;Div&period; 2&rpar; D&period; Vasiliy&&num;39&semi;s Multiset(01字典树求最大异或值)

    http://codeforces.com/contest/706/problem/D 题意:有多种操作,操作1为在字典中加入x这个数,操作2为从字典中删除x这个数,操作3为从字典中找出一个数使得与给 ...

  8. endl

    endl英语意思是end of line,即一行输出结束,然后输出下一行. endl与cout搭配使用,意思是输出结束.

  9. Oracle11g RAC安装

    双节点RAC环境,数据库 racdb 实例1:racdb1      实例2:racdb2 1.IP规划 名称             oracle-db1    oracle-db2PUBLIC I ...

  10. sicily 1001&period; Fibonacci 2

    1001. Fibonacci 2   Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn-1 + F ...