Latiao walk, every month brush question 99 yuan reward depends on everyone

preface

Today’s topic for each day is on Github (see the latest date): github.com/gzc426

Yesterday’s problem

The title

Every day a sword refers to the offer- niu Xiao.com abnormal jump steps source: Niu Xiao.com corresponding topic

Detailed questions

We can cover a larger rectangle with a smaller rectangle of 21 horizontal or vertical. How many ways are there to cover a 2* N rectangle with n small rectangles of 21 without overlapping?

The title,

Train of thought

  • Is the sword refers to the offer idea. Sum is calculated by using two variables, a and b, each of which is the Fibonacci sequence. Then a=b and b=sum, each of which is the Fibonacci sequence. Then a and B move down one position and sum is four drops.

code

public class Solution {
    public int RectCover(int target) {
        if(target == 1)
            return 1;
        if(target == 2)
            return2; Int a = 1; int b = 2; int sum = 0;for(int i=3; i<=target; i++) { sum = a+b; a = b; b = sum; // This loop is the implementation of the idea, each time I use the first two numbers to find the third number, and then the three numbers in turn, where I used to calculate the number. }returnsum; }}Copy the code

conclusion

# 2018.11.30 clock

The author, Chogory, is a computer master of Harbin Institute of Technology and a Java engineer of Baidu. Welcome to follow my wechat official account: The official account has 3T programming resources, and my friend and I (baidu C++ engineer) compiled nearly 200 MB of required Java and C++ interview experience during the autumn recruitment, and there is a leetcode punch-card group and technical exchange group every day, welcome to follow.