yoyouhappy的秘密花园
欢迎来到我的秘密花园^^
posts - 16,comments - 33,trackbacks - 0
题目是经典的DP入门,原来CTcoolL有一次拿来要做,当时还不知DP为何物,想要暴搜,现在又重新翻出来做一下

DP方程:len[ i ][ j ] = max{ len[ i-1][ j ],  len[ i ][ j-1],  len[ i+1][ j ],  len[ i ][ j+1] };

代码如下:

 1#include <iostream>
 2using namespace std;
 3 
 4int node[102][102];
 5int len[102][102];
 6int r, c;
 7int getLength( int i, int j ) 
 8{
 9    iflen[i][j] > 0 )
10        return len[i][j];
11    int max = 0;
12    if( i + 1 <= r && node[i][j] > node[i+1][j] ){
13        int x = getLength( i + 1, j ) + 1;
14        if( max < x )
15            max = x;
16    }
17    if( j + 1 <= c && node[i][j] > node[i][j+1] ){
18        int x = getLength( i, j + 1 ) + 1;
19        if( max < x )
20            max = x;
21    }
22    if( i - 1 > 0 && node[i][j] > node[i-1][j] ){
23        int x = getLength( i - 1, j ) + 1;
24        if( max < x )
25            max = x;
26    }
27    if( j - 1 > 0 && node[i][j] > node[i][j-1] ){
28        int x = getLength( i, j - 1 ) + 1;
29        if( max < x)
30            max = x;
31    } 
32    return max;
33    
34}
35int main()
36{
37
38    cin >> r >> c;
39    for ( int i = 1; i <= r; ++i ){
40        for ( int j = 1; j <= c; ++j ){
41            cin >> node[i][j];
42            len[i][j] = 0;
43        }
44    }    
45    int maxLen = 0;
46    forint i = 1; i <= r; ++i ){
47        forint j = 1; j <= c; ++j ){
48            len[i][j] = getLength( i, j );
49            if( maxLen < len[i][j] )
50                maxLen = len[i][j];
51        }
52    }
53    cout << maxLen + 1<<endl;
54    system( "pause" ); 
55}
56

posted on 2008-01-28 16:19 yoyouhappy 阅读(2463) 评论(5)  编辑 收藏 引用 所属分类: yoyo的解题报告acm/icpc

FeedBack:
# re: POJ 1088 滑雪
2008-01-28 16:29 | yoyouhappy
发现问题了,不该用len做名字的....
有犯错误了....  回复  更多评论
  
# re: POJ 1088 滑雪
2008-02-03 21:49 | ctcooll
这几天把 就是不想看
消失几天
你这个牛人总是能偷偷高出一堆题目
弄得我比较郁闷
。。。。。。。。。。。。。
我现在什么都懒得弄
算了
你快点做吧
我先去歇了
我哥回来了
天天跟他忙
累死了  回复  更多评论
  
# re: POJ 1088 滑雪[未登录]
2008-02-03 21:53 | yoyouhappy
@ctcooll
haha 你终于出现了^^
我也连着几天没碰题了,昨天大E还教育我来着 >.<
  回复  更多评论
  
# re: POJ 1088 滑雪
2008-02-03 22:27 | foxtail
代码风格要注意  回复  更多评论
  
# re: POJ 1088 滑雪[未登录]
2008-02-03 22:51 | yoyouhappy
@foxtail
请教 ^^
代码是不太优美,请提供一些建议 thx~   回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


Priceline Travel
Priceline Travel