码迷,mamicode.com
首页 > 其他好文 > 详细

poj 1088 滑雪

时间:2014-07-28 19:15:54      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   art   

http://poj.org/problem?id=1088

bubuko.com,布布扣
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 int g[200][200];
 7 int dp[200][200];
 8 int r,c;
 9 int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
10 int max1=-1;
11 
12 int dfs(int x,int y)
13 {
14     if(dp[x][y]) return dp[x][y];
15     dp[x][y]=1;
16     for(int i=0; i<4; i++)
17     {
18         int xx=x+dir[i][0];
19         int yy=y+dir[i][1];
20         if(xx>=1&&xx<=r&&yy>=1&&yy<=c&&g[x][y]>g[xx][yy])
21         {
22             dp[x][y]=max(dp[x][y],dfs(xx,yy)+1);
23         }
24     }
25     return dp[x][y];
26 }
27 
28 int main()
29 {
30     while(scanf("%d%d",&r,&c)!=EOF)
31     {
32         max1=-1;
33         memset(dp,0,sizeof(dp));
34         for(int i=1; i<=r; i++)
35         {
36             for(int j=1; j<=c; j++)
37             {
38                 scanf("%d",&g[i][j]);
39             }
40         }
41         for(int i=1; i<=r; i++)
42         {
43             for(int j=1; j<=c; j++)
44             {
45                 if(dp[i][j]==0)
46                 {
47                     dfs(i,j);
48                     max1=max(max1,dp[i][j]);
49                 }
50             }
51         }
52         printf("%d\n",max1);
53     }
54     return 0;
55 }
View Code

 

poj 1088 滑雪,布布扣,bubuko.com

poj 1088 滑雪

标签:style   blog   http   color   os   io   for   art   

原文地址:http://www.cnblogs.com/fanminghui/p/3873149.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!