题解 | #矩形覆盖#
矩形覆盖
http://www.nowcoder.com/practice/72a5a919508a4251859fb2cfb987a0e6
DP问题,矩形覆盖:状态转移方程f(n) = f(n - 1) + f(n -2)
public class Solution { public int rectCover(int target) { int fn = 0; int[] dp = new int[2]; if (2 >= target) { return target; } dp[0] = 1; dp[1] = 2; for(int i = 2; i < target; i++) { fn = dp[0] + dp[1]; dp[0] = dp[1]; dp[1] = fn; } return fn; } }