leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0552.cpp (544B)
0 class Solution {
1 static const int MOD = 1e9 + 7;
2 static int dp[2][3][100001];
4 public:
5 Solution() { memset(dp, 0xFF, sizeof(dp)); }
6 int checkRecord(int n, int a = 0, int l = 0) const {
7 if (n == 0) return 1;
8 if (dp[a][l][n] != -1) return dp[a][l][n];
10 int res = checkRecord(n - 1, a, 0);
11 if (l < 2) res = (res + checkRecord(n - 1, a, l + 1)) % MOD;
12 if (a < 1) res = (res + checkRecord(n - 1, a + 1, 0)) % MOD;
14 return dp[a][l][n] = res;
15 }
16 };
18 int Solution::dp[2][3][100001];