(记忆化搜索) FatMouse and Cheese(hdu 1078)
给n*n地图,老鼠初始位置在(0,0),它每次行走要么横着走要么竖着走,每次最多可以走出k个单位长度,且落脚点的权值必须比上一个落脚点的权值大,求最终可以获得的最大权值
(题目很容易会理解错题意,道友小心)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; #define met(a,b) (memset(a,b,sizeof(a)))
#define N 110
#define INF 0xffffff int a[N][N], dp[N][N];
int dir[][]={{-,},{,},{,-},{,}}; int DFS(int n, int k, int x, int y)
{
if(!dp[x][y])
{
int ans=; for(int i=; i<=k; i++)
{
int temp=; for(int j=; j<; j++)
{
int nx = x + dir[j][]*i;
int ny = y + dir[j][]*i; if(nx>= && nx<=n && ny>= && ny<=n && a[nx][ny]>a[x][y])
{
temp = max(temp, DFS(n, k, nx, ny));
}
}
ans = max(ans, temp);
}
dp[x][y] = ans + a[x][y];
}
return dp[x][y];
} int main()
{
int n, k; while(scanf("%d%d", &n, &k), n!=-||k!=-)
{
int i, j; met(a, );
met(dp, ); for(i=; i<=n; i++)
for(j=; j<=n; j++)
scanf("%d", &a[i][j]); printf("%d\n", DFS(n, k, , ));
} return ;
}
http://acm.hdu.edu.cn/showproblem.php?pid=1078
FatMouse and Cheese
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7774 Accepted Submission(s): 3221
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
(记忆化搜索) FatMouse and Cheese(hdu 1078)的更多相关文章
- FatMouse and Cheese HDU - 1078 dp
#include<cstdio> #include<iostream> #include<cstring> using namespace std; int n,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 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(简单记忆化搜索)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意:给出n*n的格子,每个各自里面有些食物,问一只老鼠每次走最多k步所能吃到的最多的食物 一道 ...
- HDU 1078 FatMouse and Cheese 记忆化搜索DP
直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记 ...
- !HDU 1078 FatMouse and Cheese-dp-(记忆化搜索)
题意:有一个n*n的格子.每一个格子里有不同数量的食物,老鼠从(0,0)開始走.每次下一步仅仅能走到比当前格子食物多的格子.有水平和垂直四个方向,每一步最多走k格,求老鼠能吃到的最多的食物. 分析: ...
- hdu1078 FatMouse and Cheese(记忆化搜索)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1078" target="_blank">http://acm. ...
- 记忆化搜索,FatMouse and Cheese
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1107 http://acm.hdu.edu.cn/showpro ...
- hdu1078 FatMouse and Cheese(记忆化搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1078 题目大意: 题目中的k表示横向或者竖直最多可曾经进的距离,不可以拐弯.老鼠的出发点是(1,1) ...
随机推荐
- Navicat premiu的导入和导出
对于Navicat premiu(数据库管理工具)中对于数据库的导出和导入步骤如下: 1.选择要导出的数据库->转储SQL文件->选择结构和数据或结构->选择存放的路径,即可导出成功 ...
- Informatica_(4)工作流
三.workflow执行.监控 workflow是PowerCenter的执行单元: 一个workflow包括一个或者多个session(或task). 1.session session是mappi ...
- 利用spring boot构建一个简单的web工程
1.选择Spring InitiaLizr, jdk选择好路径 2.设置项目信息 3.这一步是设置选择使用哪些组件,这里我们只需要选择web 4.设置工程名和路径
- Android.HowToDefineCustomView
Custom View Errors E1 在使用自定义CustomView时,出现以下runtime error: Android.View.InflateException: Binary XML ...
- mysql 查两个表之间的数据差集
需要查两个表之间的差集 首先,想到的是主键直接not in select mailbox_id from co_user where mailbox_id not in (select mailbox ...
- Python之路(第十一篇)装饰器
一.什么是装饰器? 装饰器他人的器具,本身可以是任意可调用对象,被装饰者也可以是任意可调用对象. 强调装饰器的原则:1 不修改被装饰对象的源代码 2 不修改被装饰对象的调用方式 装饰器的目标:在遵循1 ...
- [ASP.NET]使用Oracle.ManagedDataAccess的OracleParameter参数化和OracleDataAdapter模糊查询
今天写个查询员工的信息的demo遇到了2个问题 问题1.使用Oracle.ManagedDataAccess的OracleParameter参数化 OracleParameter 的使用(参数名要以: ...
- android开发笔记(1)
最近老师要求我们使用android开发一些东西.但是对我们而言,android是一个未知的方面.先说说我对于android的软件的基本认识,首先他很难,因为他是一个未知的领域:其次,我们只是掌握了一些 ...
- centos7修改root根目录
1.拷贝/root 原目录的东西到新目录中(包括.xxx文件) /abc 2.修改配置文件 vi /etc/passwd root:x:0:0:root:/root:/bin/bash ==> ...
- Eclipse使用Git管理项目
参考来源:https://www.cnblogs.com/wdh1995/p/7004384.html 常见问题: 1. 解决方案:http://www.360doc.com/content/18/0 ...