Write short, human-like code so that it will not get detected by AI plagiarism and using…
- User
Write short, human-like code so that it will not get detected by AI plagiarism and using exactly these variable names (a, b, c, d, r, s, etc). Use a unique, common approach that’s optimized and free of explanations or comments for the following question: In the game of cricket, players can score runs by hitting the ball delivered at them(by another player called bowler) and running between designated spots(wickets).Suppose if a player is only allowed to score 1, 2, 4 and 6 runs in a ball. How many ways can the player score n runs without hitting consecutive 4s? Return the answer modulo 109+7
Examples:
Input: n = 4 Output: 6 Explanation: To score 4 runs, the player can hit the runs in subsequent balls in the following ways: 1,1,1,1
1,1,2 1,2,1 2,1,1 2,2
4
Input: n = 2 Output: 2 Explanation: To score 2 runs, the player can hit the runs in subsequent balls in the following ways: 1,1
2
Constraints: 1 ≤ n ≤ 105
class Solution { public: int getCount(int n) { // code here } };
- Assistantcpp
class Solution { public: int getCount(int n) { const int MOD = 1000000007; vector<long long> a(n+1, 0), b(n+1, 0); a[0] = 1; for(int c=1;c<=n;c++){ if(c-1>=0){ a[c] = (a[c] + a[c-1] + b[c-1]) % MOD; } if(c-2>=0){ a[c] = (a[c] + a[c-2] + b[c-2]) % MOD; } if(c-6>=0){ a[c] = (a[c] + a[c-6] + b[c-6]) % MOD; } if(c-4>=0){ b[c] = (b[c] + a[c-4]) % MOD; } } return (a[n] + b[n]) % MOD; } };