hdu 1078(dfs记忆化搜索)
题意:容易理解...
思路:我开始是用dfs剪枝做的,968ms险过的,后来在网上学习了记忆化搜索=深搜形式+dp思想,时间复杂度大大降低,我个人理解,就是从某一个点出发,前面的点是由后面的点求出的,然后一直递归先求出后面的点,最后达到求解的效果。
代码实现:
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int map[][],count[][];
int n,k;
int b[][]={{-,},{,},{,-},{,}};
int dfs(int x,int y)
{
int i,j,temp,max=-,t1,t2;
if(count[x][y]<)
{
for(i=;i<=k;i++)
{
for(j=;j<;j++)
{
t1=x+b[j][]*i;
t2=y+b[j][]*i;
if(t1>=&&t1<=n&&t2>=&&t2<=n&&map[t1][t2]>map[x][y])
{
temp=dfs(t1,t2);
if(max<temp)
max=temp;
}
}
}
count[x][y]=max+map[x][y];
}
return count[x][y];
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&k)!=EOF&&n!=-||k!=-)
{
for(i=;i<=n;i++)
for(j=;j<=n;j++)
{
scanf("%d",&map[i][j]);
count[i][j]=-;
}
printf("%d\n",dfs(,));
}
return ;
}
hdu 1078(dfs记忆化搜索)的更多相关文章
- 不要62 hdu 2089 dfs记忆化搜索
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意: 给你两个数作为一个闭区间的端点,求出该区间中不包含数字4和62的数的个数 思路: 数位dp中 ...
- POJ1088 滑雪题解+HDU 1078(记忆化搜索DP)
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- dfs+记忆化搜索,求任意两点之间的最长路径
C.Coolest Ski Route 题意:n个点,m条边组成的有向图,求任意两点之间的最长路径 dfs记忆化搜索 #include<iostream> #include<stri ...
- hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)
pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...
- UVA 10400 Game Show Math (dfs + 记忆化搜索)
Problem H Game Show Math Input: standard input Output: standard output Time Limit: 15 seconds A game ...
- 8636 跳格子(dfs+记忆化搜索)
8636 跳格子 该题有题解 时间限制:2457MS 内存限制:1000K提交次数:139 通过次数:46 题型: 编程题 语言: G++;GCC Description 地上有一个n*m 的数 ...
- poj1088-滑雪 【dfs 记忆化搜索】
http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 79806 ...
- DFS——>记忆化搜索——>动态规划
以洛谷P1802 5倍经验日 为例 https://www.luogu.org/problem/show?pid=1802 题目背景 现在乐斗有活动了!每打一个人可以获得5倍经验!absi2011却 ...
- POJ 1191 棋盘分割 【DFS记忆化搜索经典】
题目传送门:http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submission ...
随机推荐
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
最近我做的一些项目,经常需要用到对应用程序的配置文件操作,如app.config和web.config的配置文件,特别是对配置文件中的[appSettings]和[connectionStrings] ...
- Tutorial: Model
What is a model? Across the internet the definition of MVC is so diluted that it's hard to tell what ...
- What is the difference between supervised learning and unsupervised learning?
Machine Learning is a class of algorithms which is data-driven, i.e. unlike "normal" algor ...
- POJ 3321 Apple Tree(后根遍历将树转化成序列,用树状数组维护)
题意:一棵树,有很多分叉,每个分叉上最多有1个苹果. 给出n,接下来n-1行,每行u,v,表示分叉u,v之间有树枝相连.这里数据中u相当于树中的父节点,v相当于子节点. 给出两个操作: 1.C x ...
- Android多媒体框架对音乐播放器的支持
下面介绍一下Andriod多媒体框架对开发者提供的支持有哪些. 1. MediaScannerReceiver 这个广播接收者在接收到A ...
- 李洪强漫谈iOS开发[C语言-040]-switch case
李洪强漫谈iOS开发[C语言-039]-switch case 补充:
- eclipse安装反编译插件
1. 进入http://jadclipse.sourceforge.net/wiki/index.php/Main_Page#Download 下载 net.sf.jadclipse ...
- GridView 和ListView中自适应高度
android中GridView 和ListView放在scrollView中时会默认的只有一行高这时就要我们自己计算出它的高度啦 首先是listview的 //动态设置listview的高度 pu ...
- javascript精确计算
一篇文章: 4 个用于执行高级数学计算的 JavaScript 库 numbers.js Numeric Javascript accounting.js Tangle 有时只需要加减乘法能精确,没 ...
- ubuntu下文件压缩/解压缩命令总结
.gz 解压1:gunzip FileName.gz 解压2:gzip -d FileName.gz 压缩:gzip FileName .tar.gz 解压:tar zxvf FileName.tar ...