Python solution: tricky question
\nclass Solution:\n    # an implicit DP problem\n    # For simplicity, let\'s consider the sequence "D"\n    # So we have the sequences [0,1] to permute\n    # 
```\nclass Solution:\n    # an implicit DP problem\n    # For simplicity, let\'s consider the sequence "D"\n    # So we have the sequences [0,1] to permute\n    # The valid permutation is [1,0]\n    # Now let\'s go to "DI", we add the number 2\n    # and let\'s separate the cases in which the sequence ends with different numbers\n    # We see that 0 cannot be the end, because it cannot account for the I\n    # We see that it can end with 1, by increasing every number larger than 1 by 1: [2, 0, 1]\n    # We see the same applies for ending with 2: [1, 0, 2]\n    # Now we consider the alternative "DD"\n    # We see that we can get 0 to be the end by increasing all numbers larger or equal to 0 by 1: [2,1,0]\n    # We cannot satisfy this for 1 and 2\n    # Therefore, to solve the problem, we need to build the sequences from left to right\n    # dp[i][j] = number of sequences that uses integers from [0,i] and ends with j\n    # dp[0][0] = 1\n    # If s = "D": dp[1][0] = dp[0][0] = 1; dp[1][1] = 0\n    # If s = "I": dp[1][0] = 0; dp[1][1] = dp[0][0] = 1\n    # If s = "DI": dp[2][0] = 0; dp[2][1] = dp[1][0] = 1; dp[2][2] = dp[1][0] + dp[1][1] = 1\n    # If s = "DD": dp[2][0] = dp[1][0] + dp[1][1] = 1; dp[2][1] = dp[1][0] = 0; dp[2][2] = 0\n    # If s = "DID": dp[3][0] = dp[2][0] + dp[2][1] + dp[2][2] = 0 + 1 + 1 = 2; dp[3][1] = dp[2][1] + dp[2][2] = 1 + 1 = 2; dp[3][2] =  dp[2][2] = 1; dp[3][3] = 0\n    # As we see we should calculate prefix sum or suffix sums according to whether the current character is "D" or "L" respectively to facilitate calculations\n    def numPermsDISequence(self, s: str) -> int:\n        prev, MOD = [1], pow(10,9) + 7\n        for i, c in enumerate(s):\n            if c == "D":\n                prefix = [0]*(i+2)\n                for j in range(1,i+2,1):\n                    prefix[j] = prefix[j-1] + prev[j-1]\n                    prefix[j] %= MOD\n                #print("prefix = ", prefix)\n                nxt = [0]*(i+2)\n                for j in range(i+1):\n                    nxt[j] = prefix[i+1] - prefix[j]\n            else:\n                suffix = [0]*(i+2)\n                for j in range(i,-1,-1):\n                    suffix[j] = suffix[j+1] + prev[j]\n                    suffix[j] %= MOD\n                #print("suffix = ", suffix)\n                nxt = [0]*(i+2)\n                for j in range(1,i+2):\n                    nxt[j] = suffix[0] - suffix[j]\n            prev = nxt[:]\n        return sum(prev) % MOD\n```
[]