zoukankan      html  css  js  c++  java
  • 【SHOI2002】【Luogu1434】滑雪

    problem

    solution

    codes

    //f[i][j]:以(i,j)为终点的最长路是是多少
    //f[i][j] = f(它四周的比他高的方块的最长路)+1
    #include<iostream>
    #include<cstring>
    using namespace std;
    const int maxn = 110;
    int r, c, a[maxn][maxn], f[maxn][maxn], ans;
    const int dx[] = {1,0,-1,0};
    const int dy[] = {0,-1,0,1};
    bool inside(int x, int y){return x>=1&&x<=r&&y>=1&&y<=c;}
    int dp(int x, int y){
        if(f[x][y])return f[x][y];
        int res = 0;
        for(int i = 0; i < 4; i++){
            int nx = x+dx[i], ny = y+dy[i];
            if(inside(nx,ny)&&a[nx][ny]>a[x][y]){
                res = max(res,dp(nx,ny));
            }
        }
        return f[x][y]=res+1;//我竟然因为没有更新f[x][y]导致第二个点没过。。
    }
    int main(){
        ios::sync_with_stdio(false);
        cin>>r>>c;
        for(int i = 1; i <= r; i++)
            for(int j = 1; j <= c; j++)
                cin>>a[i][j];
        for(int i = 1; i <= r; i++)
            for(int j = 1; j <= c; j++)
                ans = max(ans,dp(i,j));
        cout<<ans;
        return 0;
    }
  • 相关阅读:
    uva 532
    uva 10557
    uva 705
    uva 784
    uva 657
    uva 572
    uva 10562
    usa物价统计
    2019/6/30,道歉书
    名词收集
  • 原文地址:https://www.cnblogs.com/gwj1314/p/9444799.html
Copyright © 2011-2022 走看看