A rectangular footprint
Title Description
We can use two small rectangle 1 of sideways or vertically to cover a larger rectangle. Will the n 2- small rectangle without overlapping a cover 2 a large rectangle n, the total number of ways?
For example when n = 3, 2 rectangular block 3 has three kinds of coating method:
Outline of Solution:
When n = 1, referred to as F (1), a total of 1 method;
when n = 2, referred to as F (2 ), there are two methods;
when n = 3, referred to as F (3), is divided into three methods:
Finally it can be seen, the cover meet the Fibonacci method columns columns formula, namely:
F. (0) 0 =
F. (. 1). 1 =
F. (2) 2 =
F. (n-) = F. (. 1-n-) F. + (2-n-) n-> 2
Reference Code
# -*- coding:utf-8 -*-
class Solution:
def rectCover(self, number):
# write code here
fn = [0, 1, 2]
temp = number
while temp>=3:
fn.append(fn[-2] + fn[-1])
temp -= 1
return fn[number]