✅ C++ Simple DP Solution with comments | Easy to understand
INTUTION - Every leading 1 can generate 1 + prev binary strings either ending with 0 or 1.\nEvery 0 can generate prev binary strings ending with 0 and 1.\n\n\nL
**INTUTION** - Every leading 1 can generate 1 + prev binary strings either ending with 0 or 1.\nEvery 0 can generate prev binary strings ending with 0 and 1.\n\n```\nLet\'s take an example, 1101                              endWithOnes     endWithZeroes\nindex 0(1) -> only 1 can be generated.                         1               0\nindex 1(1) -> 1,11 can be generated.                           2               0\nindex 2(0) -> 1,11 and 10,110 can be generated                 2               2\nindex 3(1) -> 1,11,111,101,1101 and 10,110                     5               2\n```\n**Ans=** (endWithOnes)**5** + (endWithZeroes)**2** + (for 0 itself)**1** = **8**\n\n\n\n\n\n**C++ Code:**\n```\nint numberOfUniqueGoodSubsequences(string binary) {\n        bool hasZero = false;\n        int endWithZeroes=0,endWithOnes=0,mod=1e9+7;\n        \n        for(auto b:binary){\n            if(b==\'1\'){\n                endWithOnes = (endWithOnes + endWithZeroes + 1)%mod;\n            }else{\n                hasZero=true;\n                endWithZeroes = (endWithOnes + endWithZeroes)%mod;\n            }\n        }\n        \n        return (endWithOnes + endWithZeroes + hasZero)%mod;\n    }\n```\n**Please Upvote if you like the explaination : )**
['Dynamic Programming', 'C', 'C++']