8636 跳格子

该题有题解

时间限制:2457MS  内存限制:1000K
提交次数:139 通过次数:46

题型: 编程题   语言: G++;GCC

Description

    地上有一个n*m 的数字格子,每个格子有一个坐标(i,j)(其中1<=i<=n , 1<=j<=m),规定左上角为(0,0),
右下角为(n,m),你要从最左端的一列的任意位置开始跳到最右边格子外。
下面两条你跳的时候的约束规则:
一、因为你的力气有限,每次只能跳一定的距离。给定一个k 为你的弹跳力,则从(i1,j1)起跳,你能跳到
任意(i2,j2)且符合k>=(i1-i2)*(i1-i2)+( j1-j2)*( j1-j2)。
二、每次你至少要向右走一格,也就是说你不能跳到同一列的格子上戒者往回跳。再换句话说就是依次跳
到的位置的坐标中,j 必须是递增的。
每个格子里边有一个分值,当你跳到那里就可以获取到该格子的分数。
现在请你求出你最多能得多少分?
现在假设有一个5×6 的格子,你的弹跳能力为4,则如图所示你能得到17 分。

跳跃路径为(4,1)->(3,2)->(3,4)->(4,5)->(4,6)->跳出格子。

输入格式

第一行包含一个整数T,表示T 个case。
每个case 第一行包含n m k 三个整数(1<=n,m,k<=100)
接下来n行,每行m个分值,格子里的分数的绝对值小于20000

输出格式

输出最大得分。

输入样例

1
5 6 4
1 2 -1 2 1 1
2 3 -1 2 3 1
3 4 -1 2 2 3
4 2 -1 1 3 4
3 1 -1 1 1 4

输出样例

17

题解

记忆化搜索。每次从第i行第一个开始深搜,记录下搜过的点,下次如果再次搜到这个点就直接返回这个点的值就行了。
(ps:这题很多细节要注意,尽量少点一些没必要的判断,不然很容易超时)

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n,m,k;
int map[][];
int dp[][];
int DFS(int l,int r)
{
int maxn=-;
if (r==m) return map[l][r];
if (dp[l][r]) return dp[l][r];
for (int i=; i<=n; ++i)
for (int j=r+; j<=m; ++j)
if ((i-l)*(i-l)+(j-r)*(j-r)<= k)
maxn=max(maxn,DFS(i,j));
dp[l][r]=maxn+map[l][r];
return dp[l][r];
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
memset(dp,,sizeof(dp));
for (int i=; i<=n; ++i)
for (int j=; j<=m; ++j)
scanf("%d",&map[i][j]);
int maxn=-;
for (int i=; i<=n; ++i)
maxn=max(maxn,DFS(i,));
printf("%d\n",maxn);
}
return ;
}

8636 跳格子(dfs+记忆化搜索)的更多相关文章

  1. 不要62 hdu 2089 dfs记忆化搜索

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意: 给你两个数作为一个闭区间的端点,求出该区间中不包含数字4和62的数的个数 思路: 数位dp中 ...

  2. dfs+记忆化搜索,求任意两点之间的最长路径

    C.Coolest Ski Route 题意:n个点,m条边组成的有向图,求任意两点之间的最长路径 dfs记忆化搜索 #include<iostream> #include<stri ...

  3. hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)

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

  4. hdu 1078(dfs记忆化搜索)

    题意:容易理解... 思路:我开始是用dfs剪枝做的,968ms险过的,后来在网上学习了记忆化搜索=深搜形式+dp思想,时间复杂度大大降低,我个人理解,就是从某一个点出发,前面的点是由后面的点求出的, ...

  5. UVA 10400 Game Show Math (dfs + 记忆化搜索)

    Problem H Game Show Math Input: standard input Output: standard output Time Limit: 15 seconds A game ...

  6. poj1088-滑雪 【dfs 记忆化搜索】

    http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 79806 ...

  7. DFS——>记忆化搜索——>动态规划

    以洛谷P1802  5倍经验日 为例 https://www.luogu.org/problem/show?pid=1802 题目背景 现在乐斗有活动了!每打一个人可以获得5倍经验!absi2011却 ...

  8. POJ 1191 棋盘分割 【DFS记忆化搜索经典】

    题目传送门:http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  9. POJ 2704 Pascal's Travels 【DFS记忆化搜索】

    题目传送门:http://poj.org/problem?id=2704 Pascal's Travels Time Limit: 1000MS   Memory Limit: 65536K Tota ...

随机推荐

  1. 学习笔记:shell 中 [-eq] [-ne] [-gt] [-lt] [ge] [le]

    -eq           //等于 -ne           //不等于 -gt            //大于 (greater ) -lt            //小于  (less) -g ...

  2. html 页面太长滚动时,固定页面菜单标签,或者导航标签的位置,fixed/stickUp the position

    有时你曾经需要把页面上的某些东西当页面太长发滚动的时候保留置顶位置显示,或许你有别的实现方式,我这个仅供参考, 源代码: /*global $, jQuery, alert*/ (function ( ...

  3. [帖子收集]通用Windows平台(UWP)

    通用Windows平台,universal windows platform,UWP 什么是通用 Windows 平台 (UWP) 应用?(微软MSDN) 如何在通用 Windows 平台应用中使用现 ...

  4. 【小技巧】C#的saveFileDialog和openFileDialog的用法总结

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. @Autowired与 @Resource

    @Autowired, @Resource 1.注解类型: Autowired可用于构造器.属性.方法.注解 @Target({ElementType.CONSTRUCTOR, ElementType ...

  6. Little Puzzlers–List All Anagrams in a Word

    The Solution A major hint is in the fact we are given a dictionary.  Because we are given this dicti ...

  7. 理解iaas paas saas三种云服务区别

    其实搞懂这个问题也不难,我们可以把云计算理解成一栋大楼,而这栋楼又可以分为顶楼.中间.低层三大块.那么我们就可以把Iass(基础设施).Pass(平台).Sass(软件)理解成这栋楼的三部分.基础设施 ...

  8. C# 手机格式验证

    C# 手机格式验证 //电信手机号码正则 Regex dReg = new Regex(@"^1[3578][01379]\d{8}$"); //联通手机号正则 Regex tRe ...

  9. CSS预处理器 Less Sass,Scss 编译 Sourcemap调试

    sass.less和stylus的安装使用和入门实践     SASS用法指南    Sass Basics CSS预处理器 css preprocessor 预处理器即preprocessor,预处 ...

  10. vs2008编译FileZilla客户端源码

    vs2008编译FileZilla客户端源码 下载FileZilla客户端源码,下载地址https://download.filezilla-project.org/. FileZilla客户端解决方 ...