← 回題庫

卷別

資料結構與演算法(A)

選擇

國立臺灣大學 2021 · 考試 · 第 2 題

考科演算法

(5 points) A typical dynamic programming example is the snake sequence. Given a grid of numbers, find the maximum length snake sequence. A snake sequence is made up of adjacent numbers in the grid such that for each number, the number on the right or the number below it is +1+1 or −1-1 its value. At location (x,y)(x, y), you can move right (x+1,y)(x+1, y) or move down (x,y+1)(x, y+1) if that number is ±1\pm 1. The length of a snake sequence is defined as the number of moves. Given the following grid (MM rows, NN columns; rows top-to-bottom):

9, 6, 5, 2
8, 7, 6, 5
7, 3, 1, 6
1, 1, 1, 7

The maximum LENGTH of snake sequence is?

  • (A)
    6
  • (B)
    7
  • (C)
    5
  • (D)
    4

標準解析

AI 已複查