poj 1088滑雪
经典的动态规划问题:
1 #include<iostream> 2 3 using namespace std; 4 5 int b[101][101]; 6 int d[101][101]; 7 int r,c; 8 9 10 int dp(int i,int j) 11 { 12 int max=0; 13 14 if(d[i][j]!=0) 15 return d[i][j]; 16 17 //四个方向是否合适 18 if(i-1>=0) 19 { 20 if(b[i-1][j]<b[i][j]) 21 { 22 int temp=dp(i-1,j); 23 if(max<temp) max=temp; 24 } 25 } 26 27 if(i+1<r) 28 { 29 if(b[i+1][j]<b[i][j]) 30 { 31 int temp=dp(i+1,j); 32 if(max<temp) max=temp; 33 } 34 } 35 36 if(j-1>=0) 37 { 38 if(b[i][j-1]<b[i][j]) 39 { 40 int temp=dp(i,j-1); 41 if(max<temp) max=temp; 42 } 43 } 44 45 if(j+1<c) 46 { 47 if(b[i][j+1]<b[i][j]) 48 { 49 int temp=dp(i,j+1); 50 if(max<temp) max=temp; 51 } 52 } 53 54 return d[i][j]=max+1; 55 } 56 57 int main() 58 { 59 int i,j; 60 cin>>r>>c; 61 for(i=0;i<r;++i) 62 for(j=0;j<c;++j) 63 cin>>b[i][j]; 64 memset(d,0,sizeof(d)); 65 for(i=0;i<r;++i) 66 for(j=0;j<c;++j) 67 dp(i,j); 68 int max=0; 69 for(i=0;i<r;++i) 70 for(j=0;j<c;++j) 71 if(d[i][j]>max) max=d[i][j]; 72 cout<<max<<endl; 73 return 0; 74 75 }
转载于:https://www.cnblogs.com/redlight/archive/2012/04/13/2445559.html
poj 1088滑雪相关推荐
- POJ 1088 滑雪(输出对比)
http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 68159 ...
- poj 1088 滑雪(线性DP)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 81553 Accepted: 30437 Description ...
- poj 1088 滑雪 详解
http://poj.org/problem?id=1088 这是一道dp入门题,不过我一直没想明白应该怎么dp.今天,在做自己学校oj的算法基础题时看到这题,标注着dp的分类,加上我一直都比较喜欢做 ...
- 动态规划 POJ 1088 滑雪
Description Michael 喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知 ...
- POJ 1088 滑雪 (动规)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 75664 Accepted: 28044 Description Mich ...
- POJ - 1088 滑雪 【DP】【DFS】
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- poj 1088 滑雪 (dp)
题目链接 题意就不多解释了,题目思路很简单,搜索就行了,但是暴搜会TLE,但是对于每一个dfs(X, Y),如果参数一样的话结果也是一样的,我们用一个二维数组去保存每次计算的位置的结果,最后从所有的解 ...
- I - 滑雪 POJ - 1088(深搜,记忆化搜索)
Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道载一个区域中最长底滑坡. ...
- POJ 1088(滑雪)
题目链接 题意 给一个R.C数字矩阵,每个点可以向上下左右且比自己小的方向移动,问最长移动距离 AC dfs + 记忆 #include <iostream> #include <a ...
最新文章
- 跳出数据计算拯救人智能
- win10安装JDK cmd中可以运行java,但不能用javac,解决方案
- Gentoo - X11 forwarding request failed on channel 0
- 数十家公司超10亿数据外泄,2019年数据安全不再“纸上谈兵”
- redis php怎么使用教程,PHP 使用redis
- 判断给定数字n是否为素数(质数)
- Linq学习(零)-错误汇总
- 网页连接的服务器失败是怎么回事啊,网页怎么连接服务器失败
- css 居中50%,CSS中的translate(-50%,-50%)实现水平垂直居中效果
- html不用ajax怎么提交,停止HTML中JS AJAX功能提交按钮
- 深入浅出数据分析 - 数据分析引言
- 回归、自回归、循环神经网络(RNN)、LSTM
- Android检测wifi信号强度,检测网络是否通畅
- SpringSocial整合QQ授权登录
- 【ROS2原理11】C++编程的要点
- 编写第一个JavaFX界面
- 如何基于Python写一个TCP反向连接后门
- 【游戏面包屑】开发类职业攻略1.0
- akka java api中文_akka入门 (1):akka简介
- 如何使用笔记本共享wifi给移动设备并ss上网