首页 / 客观题库

80046 - 雪地探险(46~50题)

题目(材料题)

在一片矩形雪地中,每个格子有一个海拔高度。滑雪爱好者可以从任意格子出发,每次只能移动到上下左右相邻且海拔严格低于当前格子的海拔高度(只能下坡,不能上坡或平坡),且不能重复经过同一个格子。在整个雪地上,最多能经过多少个格子(包含起点)?

01 #include <iostream>

02 #include <algorithm>

03 using namespace std;

04

05 const int M = 55;

06 int a[M][M];

07 int path[M][M];

08 int n, m;

09 int dx[4] = {0, 0, 1, -1};

10 int dy[4] = {1, -1, 0, 0};

11

12 int dfs(int x, int y) {

13     ①

14         return path[x][y];

15     ②

16     for (int i = 0; i < 4; i++) {

17         int nx = x + dx[i];

18         int ny = y + dy[i];

19         if ( ③ ){

20              ans = ④

21         }

22     }

23     return path[x][y] = ans;

24 }

25

26 int main() {

27     cin >> n >> m;

28     for (int i = 0; i < n; i++)

29         for (int j = 0; j < m; j++)

30             cin >> a[i][j];

31     for (int i = 0; i < n; i++)

32         for (int j = 0; j < m; j++)

33             path[i][j] = -1;

34     int max_len = 0;

35     for (int i = 0; i < n; i++)

36         for (int j = 0; j < m; j++)

37              max_len = ⑤

38     cout << max_len << endl;

39     return 0;

40 }

||
( 单选 )

① 处应填(     )

A if (path[x][y] = -1)

B if (path[x][y] == -1)

C if (path[x][y] != -1)

D if (path[x][y] > -1)

( 单选 )

② 处应填(     )

A int ans = 0;

B int ans = 1;

C int ans = -1;

D int ans;

( 单选 )

 ③ 处应填(     )

A nx >= 0 && nx < n && ny >= 0 && ny < m && a[nx][ny] < a[x][y]

B nx >= 0 && nx < n && ny >= 0 && ny < m && a[nx][ny] > a[x][y]

C nx >= 0 && nx < n && ny >= 0 && ny < m && a[nx][ny] <= a[x][y]

D nx >= 0 && nx <= n && ny >= 0 && ny <= m && a[nx][ny] < a[x][y]

( 单选 )

④ 处应填 (     )

A max(ans, dfs(nx, ny));

B max(ans, 1 + dfs(nx, ny));

C ans + dfs(nx, ny);

D max(1, dfs(nx, ny));

( 单选 )

⑤ 处应填(     )

A max(max_len, path[i][j]);

B max_len + dfs(i, j);

C max(max_len, a[i][j]);

D max(max_len, dfs(i, j));

意见反馈

    最多上传3张图片,格式为JPG、PNG、JPEG,单张不超过5MB

    注册

    发送验证码

    密码必须包含数字、字母和特殊字符

    找回密码

    发送验证码

    密码必须包含数字、字母和特殊字符

    运行 ID:67149

    • 测试点1:Accepted
    • 用时:0 ms
    • 内存:288 kb
    • 测试点2:Accepted
    • 用时:0 ms
    • 内存:288 kb
    输入
    203
    输出
    203

    test

    测评信息

    错误.in文件下载

    错误.out文件下载

    运行 ID:67149

    2019-01-24 15:06:36