Q2 Tutorial An easy dp problem, for dp[i], means how many good string of length i.
Init dp[zero] = 1, dp[one] = 1 (if one == zero, then dp[one] = 2);
So dp[i] = dp[i - zero] + dp[i - one]. After calculate all dp, sum up dp[low] to dp[high].
Accepted Code class Solution { public: long long dp[100005]; int countGoodStrings(int low, int high, int zero, int one) { memset(dp, 0, sizeof(dp)); dp[zero]++; dp[one]++; for(int i = min(zero, one); i <= high; ++i){ if(i > zero) dp[i] += dp[i - zero]; if(i > one) dp[i] += dp[i - one]; dp[i] %= 1000000007; } long long ans = 0; for(int i = low; i <= high; ++i){ ans += dp[i]; ans %= 1000000007; } return ans; } }; Q3 Tutorial First, from root 0, bfs all tree to find where bob is.
If you get any problem of my code or you find something wrong, just leave a comment or contact with me, I’ll response you as fast as I can if I see it.
If this tutorial helps you well, you can subscribe my website, every time I update any Tutorial, I’ll send an email to all subscribers.
10-31 766. Toeplitz Matrix Difficulty: Easy Accepted Code class Solution { public: bool isToeplitzMatrix(vector<vector<int>>& matrix) { vector<int> n[int(matrix.
D. Guess The String Problem summary The Jury chosen a stringS consisting of n characters; each character of S is a lowercase Latin letter.
You may ask query in two types:
1 i - query for the letterSi 2 l r - query the size of character set of Sl,Sl+1,......,Sr You are allowed to ask no more than 26 queries of the first type, and no more than 6000 queries of the second type.