skiing
时间限制:3000 ms | 内存限制:65535 KB 难度:5- 描述
-
Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子中,一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上,这是最长的一条。
- 输入
-
第一行表示有几组测试数据,输入的第二行表示区域的行数R和列数C(1 <= R,C <= 100)。下面是R行,每行有C个整数,代表高度h,0<=h<=10000。
后面是下一组数据;
- 输出
- 输出最长区域的长度。
- 样例输入
-
1 5 5 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
- 样例输出
-
25
#include "stdio.h" #include "string.h" #define MAXN 10000+10 #define N 100+10 int area[N][N],state[N][N],r,c; //r行数,c列数 int max(int a,int b,int c,int d){ if(a d a:d; } int dfs(int x,int y,int front){ //front表示从front高度滑下来 if(x<1 || y<1 || x>r || y>c || front<=area[x][y]) return 0; if(state[x][y]>=0) return state[x][y]; state[x][y]=max(dfs(x-1,y,area[x][y]),dfs(x+1,y,area[x][y]),dfs(x,y-1,area[x][y]),dfs(x,y+1,area[x][y]))+1; return state[x][y]; } int main() { int n,result; scanf("%d",&n); if(n<1) return 0; while(n--){ result=0; scanf("%d %d",&r,&c); memset(state,-1,sizeof(state)); for(int x=1;x<=r;x++){ for(int y=1;y<=c;y++){ scanf("%d",&area[x][y]); } } for(int x=1;x<=r;x++){ for(int y=1;y<=c;y++){ int temp=dfs(x,y,MAXN); result=result>temp result:temp; } } printf("%d\n",result); } return 0; }
- <script type="text/java script">BAIDU_CLB_fillSlot("771048");
- 点击复制链接 与好友分享! 回本站首页 <script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
<script type="text/java script" id="bdshare_js" data="type=tools&uid=12732"> <script type="text/java script" id="bdshell_js"> <script type="text/java script"> var bds_config = {'snsKey':{'tsina':'2386826374','tqq':'5e544a8fdea646c5a5f3967871346eb8'}}; document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js cdnversion=" + Math.ceil(new Date()/3600000) - 您对本文章有什么意见或着疑问吗?请到 论坛讨论您的关注和建议是我们前行的参考和动力
- 上一篇: [Leetcode]Roman to Integer
- 下一篇: 最后一页
- 相关文章
- <script type="text/java script">BAIDU_CLB_fillSlot("182716");
- <script type="text/java script">BAIDU_CLB_fillSlot("517916");
- 图文推荐
<iframe src="http://www.2cto.com/uapi.php tid=288242&catid=339&title=TllPSiAxMCBza2lpbmc=&forward=http://www.2cto.com/kf/201403/288242.html" width="100%" height="100%" id="comment_iframe" name="comment_iframe" frameborder="0" scrolling="no">
- <script type="text/java script">BAIDU_CLB_fillSlot("771057");



