Generic Solution for DP, can be extended to k different characters.
\nclass Solution {\n    int mod = (int)1e9 + 7;\n    public int numberOfUniqueGoodSubsequences(String binary) {\n        int n = binary.length();\n        int [
```\nclass Solution {\n    int mod = (int)1e9 + 7;\n    public int numberOfUniqueGoodSubsequences(String binary) {\n        int n = binary.length();\n        int []dp = new int[n + 1];\n\n        dp[0] = 1;\n        boolean []foundZero = new boolean[n];\n        int []last = new int[2];\n        Arrays.fill(last, -1);\n        Arrays.fill(foundZero, true);\n        \n        for(int i=0; i<n; i++) {\n            if(binary.charAt(i) != \'0\') foundZero[i] = false;\n            else break;\n        }\n        \n        for(int i=1; i<=n; i++) {\n            int val = binary.charAt(i - 1) - \'0\';\n            dp[i] = dp[i-1] * 2 % mod;\n            if(val == 0) {\n                if(last[0] != -1) {\n                    dp[i] -= dp[last[0]];\n                    dp[i]--;\n                    if(last[0] > 0 && foundZero[last[0] - 1]) {\n                        dp[i]++;\n                    }\n                }\n            }\n            else {\n                if(i>=2 && foundZero[i-2]) dp[i]--; \n                if(last[1] != -1) {\n                    dp[i] -= dp[last[1]];\n                    if(last[1] > 0 && foundZero[last[1] - 1]) {\n                        dp[i] += 1;\n                    }\n                }\n            }\n            dp[i] %= mod;\n            last[val] = (i - 1);\n        }\n        dp[n]--;\n        if(dp[n] < 0) dp[n] += mod;\n        return dp[n]; \n    }\n}\n```
[]