C++ | Dynamic Programming - Bottom UP | TIME - O(N) AND SPACE -O(N)
Similar to Distinct Subsequences 2\n\nclass Solution {\npublic:\n    int numberOfUniqueGoodSubsequences(string binary) {\n        int n=binary.size();\n        
**Similar to Distinct Subsequences 2**\n```\nclass Solution {\npublic:\n    int numberOfUniqueGoodSubsequences(string binary) {\n        int n=binary.size();\n        int mod=1e9+7;\n        vector<long> dp(n,0);\n        int a=-1, b=-1;\n        bool flag=false;\n        \n        if(binary[0]==\'0\'){\n            a=0;\n        }else{\n            b=0;\n            dp[0]=1;\n        }\n        \n        for(int i=1; i<n; i++){\n            char ch=binary[i];\n            if(ch==\'0\'){\n                if(a==-1){\n                    dp[i]=2*dp[i-1]%mod;\n                }else{\n                    if(a!=0)\n                        dp[i]=(2*dp[i-1]%mod-dp[a-1]+mod)%mod;\n                    else\n                        dp[i]=2*dp[i-1]%mod;\n                }\n                a=i;\n            }else{\n                if(b==-1)\n                    dp[i]=1+2*dp[i-1]%mod;\n                else{\n                    if(b!=0)\n                        dp[i]=(2*dp[i-1]%mod-dp[b-1]+mod)%mod;\n                    else\n                        dp[i]=2*dp[i-1]%mod;\n                }\n\n                b=i;\n            }\n        }\n        \n        \n        \n        return a>=0 ? dp[n-1]+1 : dp[n-1];\n    }\n};\n```
['Dynamic Programming', 'C']