[SHOI2002]滑雪 (记忆化搜索模版)

题目链接:https://www.luogu.com.cn/problem/P1434

想法:

记忆化搜索板子题:

#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <math.h>
#include <cstdio>
#include <iomanip>
#include <time.h>
#include <bitset>
#include <cmath>
#include <sstream>
#include <iostream>
#include <cstring>

#define LL long long
#define ls nod<<1
#define rs (nod<<1)+1
#define pii pair<int,int>
#define mp make_pair
#define pb push_back

const double eps = 1e-10;
const int maxn = 100 + 10;
const LL mod = 1e9 + 7;
const LL INF = 1e18;

int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}
using namespace std;

int mapp[maxn][maxn];
int f[maxn][maxn];
int n,m;
int dir[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};

inline int dfs(int x,int y,int last) {
    if (f[x][y])
        return f[x][y];
    f[x][y] = 1;
    for (int i = 0;i < 4;i++) {
        int xx = x + dir[i][0];
        int yy = y + dir[i][1];
        if (mapp[xx][yy] < last && xx >= 1 && xx <= n && yy >= 1 && yy <= n) {
            dfs(xx,yy,mapp[xx][yy]);
            f[x][y] = max(f[x][y],f[xx][yy]+1);
        }
    }
    return f[x][y];
}

int main() {
    cin >> n >> m;
    for (int i = 1;i <= n;i++) {
        for (int j = 1;j <= m;j++)
            cin >> mapp[i][j];
    }
    int ans = 0;
    for (int i = 1;i <= n;i++) {
        for (int j = 1;j <= m;j++) {
            ans = max(ans,dfs(i,j,mapp[i][j]));
        }
    }
    cout << ans << endl;
    return 0;
}

原文地址:https://www.cnblogs.com/-Ackerman/p/12431484.html

时间: 2024-08-02 21:33:33

[SHOI2002]滑雪 (记忆化搜索模版)的相关文章

[ACM] poj 1088 滑雪 (记忆化搜索DFS)

求n*m网格内矩形的数目[ACM] poj 1088 滑雪 (记忆化搜索DFS),布布扣,bubuko.com

POJ 1088 滑雪(记忆化搜索+dfs)

滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 83489   Accepted: 31234 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道载一个区域中最长底滑坡.区域由一个二维数组给出.数组的每个数字代表点的高度.下面是一个例子 1 2 3 4 5 16 17

tyvj 1004 滑雪 记忆化搜索

滑雪 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://www.tyvj.cn/p/1004 Description trs喜欢滑雪.他来到了一个滑雪场,这个滑雪场是一个矩形,为了简便,我们用r行c列的矩阵来表示每块地形.为了得到更快的速度,滑行的路线必须向下倾斜.    例如样例中的那个矩形,可以从某个点滑向上下左右四个相邻的点之一.例如24-17-16-1,其实25-24-23…3-2-1更长,事实上这是最长的一条. Input 输入文件

滑雪 记忆化搜索

题目: 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 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.在上面的例子中,一条可

poj1088 滑雪 记忆化搜索

我是渣渣 我是渣渣 ....记忆化搜索 看了学长的代码 和算法竞赛入门经典这本书才勉勉强强看懂点... #include <stdio.h> #include <string.h> int dir[4][2]={1,0,-1,0,0,1,0,-1};//方向 int dp[101][101],map[101][101]; int m,n; int max(int x,int y) { return x>y?x:y; } bool limit(int x,int y)//是否出

POJ 1088 滑雪 记忆化搜索

解析:状态d[i][j]代表r=i , c=j这个位置能滑的最大长度.深搜+备忘录 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int maxn=100+5; int R,C; int a[maxn][maxn]; int d[maxn][maxn]; int dr[]={0,-1,0,1};

POJ 1088滑雪 记忆化搜索

#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack> #include <cstdlib> #include <cmath> #include <set> #include <map> #include <vector> #include <cstri

poj1088滑雪(dfs+记忆化搜索、备忘录)

题目信息: 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 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.在上面的例子中,一条可滑

POJ 1088 滑雪(记忆化搜索)

滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 92384   Accepted: 34948 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道载一个区域中最长底滑坡.区域由一个二维数组给出.数组的每个数字代表点的高度.下面是一个例子 1 2 3 4 5 16 17