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

Implementation of PHP Facades

Example <?php class RealRoute{ public function get(){ Echo’Get me’; } } class Facade{ public static $resolvedInstance; public static $app; public static function __callStatic($method,$args){ $instance = static::getFacadeRoot(); if(!$instance){ throw new RuntimeException(‘A facade root has not been set.’); } return $instance->$method(…$args); } // Get the Facade root object public static function getFacadeRoot() { return static::resolveFacadeInstance(static::getFacadeAccessor()); } protected […]