C++ | DP
class Solution {\nint M = 1e9 + 7;\npublic:\n    int numberOfUniqueGoodSubsequences(string binary) {\n        \n        int n = binary.size();\n        vector d
class Solution {\n`    int M = 1e9 + 7;`\npublic:\n    int numberOfUniqueGoodSubsequences(string binary) {\n        \n        int n = binary.size();\n        vector<long long> dp(n + 1, 0);\n        int prev_zero = 0, prev_one = 0;\n        \n        int i = 1;\n        for(; i <= n && binary[i - 1] == \'0\'; i++);\n        \n        if(i > n)\n            return 1;\n        \n        dp[i] = 1;\n        prev_one = i - 1;\n                \n        bool zero_flag = i > 1;\n        for(i++; i <= n; i++)\n        {\n            dp[i] = 2 * dp[i - 1];\n            \n            if(binary[i - 1] - \'0\')\n                dp[i] -= dp[prev_one], prev_one = i - 1;\n            else\n                dp[i] -= dp[prev_zero], prev_zero = i - 1, zero_flag = true;\n            \n            if(dp[i] < 0)\n                dp[i] += M;\n            \n            dp[i] %= M;\n        }\n        \n        return (dp[n] + zero_flag) % M;\n    }\n};
['Dynamic Programming', 'C']