代码:
!!动态规划基础版完结撒花🎉
- class Solution {
- public int numTilings(int n) {
- long MOD = 1000000007;
- int[] dp = new int[n+1];
- dp[0]=1;
- for(int i=1;i<=n;i++){
- dp[i]+=dp[i-1]%MOD;
- dp[i]%=MOD;
- if(i>=2){
- dp[i]+=dp[i-2]%MOD;
- dp[i]%=MOD;
- }
- for(int j=0;2*j+3<=i;j++){
- dp[i]+=dp[i-3-2*j]*2%MOD;
- dp[i]%=MOD;
- }
- for(int j=2;2*j<=i;j++){
- dp[i]+=dp[i-2*j]*2%MOD;
- dp[i]%=MOD;
- }
- dp[i]%=MOD;
- }
- return dp[n]%=MOD;
- }
- }