zoukankan      html  css  js  c++  java
  • 一本通 1280:【例9.24】滑雪

    滑雪

    记忆化搜索


    Code:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    //Mystery_Sky
    //
    #define M 500
    #define INF 0x3f3f3f3f
    int f[M][M];
    int r, c, map[M][M], ans;
    int dx[] = {0, 0, 1, -1};
    int dy[] = {1, -1, 0, 0};
    
    int dfs(int x, int y)
    {
    	if(f[x][y]) return f[x][y];
    	int maxx = 1;
    	int step = 0;
    	for(int i = 0; i < 4; i++) {
    		int xx = x + dx[i];
    		int yy = y + dy[i];
    		step = 0;
    		if(xx <= 0 || xx > r || yy <= 0 || yy > c) continue;
    		if(map[xx][yy] < map[x][y])	step = dfs(xx, yy) + 1;
    		maxx = max(maxx, step);
    	}
    	f[x][y] = maxx;
    	return f[x][y];
    }
    
    int main() {
    	scanf("%d%d", &r, &c);
    	for(int i = 1; i <= r; i++)
    		for(int j = 1; j <= c; j++) scanf("%d", &map[i][j]);
    	for(int i = 1; i <= r; i++)
    		for(int j = 1; j <= c; j++) {
    			f[i][j] = dfs(i, j);
    			ans = max(ans, f[i][j]);
    		}
    	printf("%d
    ", ans);
    	return 0;
    }
    
    唯愿,青春不辜负梦想,未来星辰闪耀
  • 相关阅读:
    Windows下输入法全角符,半角符的切换
    hdu 2546 饭卡
    hdu 1712 ACboy needs your help
    hdu 3033 I love sneakers!
    hdu 1171 Big Event in HDU
    hdu 1114 Piggy-Bank
    HDU 1058 Humble Numbers
    hdu 1297
    hdu 2050
    hdu 2563
  • 原文地址:https://www.cnblogs.com/Benjamin-cpp/p/11025626.html
Copyright © 2011-2022 走看看