C++ DP Solution with O(n) time and O(1) space
My thought process:\n1. The statement of "the result might too big and use the modulo 1e9 + 7" confirms that it must be  a DP problem.\n2. I then tried to first
My thought process:\n1. The statement of "the result might too big and use the modulo 1e9 + 7" confirms that it must be  a DP problem.\n2. I then tried to firstly build the base cases of and define the state transitions\n\n```\nclass Solution {\npublic:\n    int numberOfUniqueGoodSubsequences(string binary) {\n        const int MOD = 1e9 + 7;\n        int dp_zero = 0, dp_one = 0;\n\t\t// f(i, 0) = the number of unique subsequences starting with 0 (note that these subsequences are not good since they all have the staring zeros)\n\t\t// f(i, 1) = the number of good unique subsequences starting with 1\n\t\t// Once we have the base cases the new states can be calculated as in the code below\t\t\n        \n        dp_zero = binary.back() == \'0\' ? 1 : 0;        \n        dp_one = binary.back() == \'1\' ? 1 : 0;\n        bool zero = binary.back() == \'0\';\n        for (int i = binary.size() - 2; i >= 0; --i) {\n            if (binary[i] == \'0\') {\n\t\t\t\t// With the new 0, all the f(i + 1, 1) can be used to derive a new subsequence. f(i + 1, 0) can also be used to derive a longer subsequence therefore add 1 here.\n\t\t\t\t\n                dp_zero = dp_zero + 1 + dp_one;\n            }\n            else {                \n                dp_one = dp_one + 1 + dp_zero;\n            }\n\t\t\t// Handle the single digit sequence with 0 only\n            zero |= binary[i] == \'0\';\n            dp_zero %= MOD;\n            dp_one %= MOD;            \n        }\n        return (dp_one + zero) % MOD;\n    }\n};\n```
['Dynamic Programming']