leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0552.cpp (544B)


      1 class Solution {
      2     static const int MOD = 1e9 + 7;
      3     static int dp[2][3][100001];
      4 
      5   public:
      6     Solution() { memset(dp, 0xFF, sizeof(dp)); }
      7     int checkRecord(int n, int a = 0, int l = 0) const {
      8         if (n == 0) return 1;
      9         if (dp[a][l][n] != -1) return dp[a][l][n];
     10 
     11         int res = checkRecord(n - 1, a, 0);
     12         if (l < 2) res = (res + checkRecord(n - 1, a, l + 1)) % MOD;
     13         if (a < 1) res = (res + checkRecord(n - 1, a + 1, 0)) % MOD;
     14 
     15         return dp[a][l][n] = res;
     16     }
     17 };
     18 
     19 int Solution::dp[2][3][100001];