[Daily Blue Bridge] The real question of the 12th, 13th provincial Java group "Revitalize China"

Hello, I am the little gray ape, a programmer who can write bugs!

Welcome everyone to pay attention to my column " Daily Blue Bridge ". The main function of this column is to share with you the real questions of the Blue Bridge Cup provincial competitions and finals in recent years, analyze the algorithm ideas, data structures and other content that exist in it, and help you learn To more knowledge and technology!

Title: Revitalizing China

Xiao Ming participated in a fun sports meeting in the school, one of the events was: jumping grid

There are some grids drawn on the ground, and a number is written in each grid, as shown below: (also see p1.jpg)

Start from me

I started revitalizing

Starting to revitalize

Revitalize China

During the game, I stand in the grid with the word "from" in the upper left corner. I can jump to the adjacent grid horizontally or vertically, but not to the diagonal grid or other positions. I have to jump to "Hua". "The word ends,

The route required to be skipped just constitutes the sentence "starting from me to revitalize China"

Please help Xiao Ming calculate how many possible jumping routes he has in total?

The answer is an integer, please submit the number directly through the browser

Note: Do not submit the answering process, or other supporting explanation content

Problem-solving ideas:

This question can be solved by referring to the recursive thinking. We can analyze it according to the graph given in the question. The next step and the next part of each grid meet the requirements.

Therefore, we can turn the question into: find out whether there is a grid below or to the right of each grid. If there is a grid, add 1 to the number of methods. When the boundary is reached, there is only one way, which is down or to the right. Find out how many ways there are for each grid, and finally find out how many ways there are for the grid with coordinates (0,0).

At the same time, you can also refer to the idea of ​​deep search of the tree in the data structure

Answer source code:

package 一三年省赛真题;

public class Year2013_Bt3 {

	public static void main(String[] args) {
		int answer = f(0,0);//从(0,0)点开始
		System.out.println(answer);
	}
	
	/**
	 * 计算在当前点上有多少种走法
	 * @param i j 横纵坐标
	 * @return 该点上可以走的方法
	 * */
	public static int f(int i,int j) {
		if (i==3||j==4) {
			return 1;
		}
		return f(i, j+1) + f(i+1, j);
	}

}

 

Sample output:

 

There are deficiencies or improvements, and I hope my friends will leave a message and learn together!

Interested friends can follow the column!

Little Grey Ape will accompany you to make progress together!

Finally, I am participating in the selection of the 2020 Blog Star, please help me to vote for it!

Vote link: https://bss.csdn.net/m/topic/blog_star2020/detail?username=weixin_44985880

Guess you like

Origin blog.csdn.net/weixin_44985880/article/details/112984431