Huawei OD Computer Test Real Questions-Jumping Grid-2023 OD Unified Examination (Paper B)

Topic description:

Xiao Ming plays a lattice jumping game with his friends. There are n consecutive lattice blocks, and each lattice has a different score. Children can choose to jump from any lattice, but they cannot jump consecutive lattice blocks, nor can they jump back;

Given an array of non-negative integers representing the scores of each grid, calculate the highest score that can be obtained.

Enter description:

Given a numerical example, such as:

1 2 3 1

Output description:

Output the highest score that can be obtained, such as:

4

Additional instructions:

1 <= nums.length <= 100 

0 <= nums[i] <= 1000

Example 1

enter:

1 2 3 1

Output:

4

illustrate:

Choose to jump the first grid and the third grid

Example 2

enter:

2 7 9 3 1

Output:

12

illustrate:

2+9+1=12

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] ss = s.

Guess you like

Origin blog.csdn.net/2301_76848549/article/details/132778315