一定要注意的是,覆盖的时候不是随便覆盖的,要搞清楚大矩形的样子是 2 * n ,然后采用递推的方式从n = 1,2,3,4,5去找规律,可以通过动态规划去解决问题,状态转移数组:dp[i] = dp[i-1] + dp[i-2];
public int rectCover(int target) { if (target <= 2){ return target; } int[] dp = new int[target+1]; dp[1] = 1; dp[2] = 2; for (int i = 3; i <= target ; i++) { dp[i] = dp[i - 1] + dp[i - 2]; } return dp[target]; }