Implementation of Rectangular Coverage Instances in Java Code

Time:2019-8-10

subject

We can cover larger rectangles horizontally or vertically with a small rectangle of 2 x 1. How many methods are there to cover a large rectangle of 2 *n with n small rectangles of 2 *1 without overlapping?

The Core Thought of Procedure

2* (n-1) blocks are covered by small squares in only one way (vertical), and 2* (n-2) squares are covered by small squares in only one way (horizontal).

perhaps

  • For the first time, the small squares are placed vertically, and the rest are arranged in F (target – 1).
  • For the first time, the small squares are placed horizontally, and the rest are arranged in F (target – 2)

Code


public class Solution {
public int RectCover(int target) {
if(target <= 0 ){
return 0;
}
if(target == 1){
return 1;
}else if(target == 2){
return 2;
}else{
return RectCover(target - 1) + RectCover(target - 2);
}
}
}

The above is the whole content of this article. I hope it will be helpful to everyone’s study, and I hope you will support developpaer more.

Recommended Today

Manjaro uses SS method (requires nodejs environment)

Just installed manjaro, need to installshadowsocks-qt5+Proxy SwitchyOmega, but the latest Chrome has long blocked the installation of non Google store CRX channels. Here is my solution, which is troublesome but usable. If you are familiar with NPM commands in nodejs, you won’t find it troublesome, because nodejs is used for compilation. Preparation environment: A VPS […]