Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int countSpecialSubsequences(vector<int>& nums) {
- long long int dp[3];
- memset(dp, 0, sizeof dp);
- long long mod = int(1e9)+7;
- for(int i=0; i<nums.size(); i++){
- int a = nums[i];
- if(a == 0)
- dp[a] = (2LL*dp[a]+1)%mod;
- else
- dp[a] = (2LL*dp[a]+dp[a-1])%mod;
- }
- return dp[2];
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment