nikunjsoni

790

Jun 14th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int numTilings(int n) {
  4.         vector<long long int> dp1(4), dp2(4);
  5.         dp1[0] = 1;
  6.        
  7.         int mod = int(1e9)+7;
  8.         for(int i=0; i<n; i++){
  9.             dp2[0] = (dp1[0]+dp1[3])%mod;
  10.             dp2[1] = (dp1[0]+dp1[2])%mod;
  11.             dp2[2] = (dp1[1]+dp1[0])%mod;
  12.             dp2[3] = (dp1[1]+dp1[2]+dp1[0])%mod;
  13.             dp1 = dp2;
  14.         }
  15.         return dp2[0];
  16.     }
  17. };
Advertisement
Add Comment
Please, Sign In to add comment