Simple C++ solution
\nclass Solution {\npublic:\n    int numPermsDISequence(string S) {\n        int n = S.length(), mod = 1e9 + 7;\n        vector<vector<int>> dp(n + 1, vector<in
```\nclass Solution {\npublic:\n    int numPermsDISequence(string S) {\n        int n = S.length(), mod = 1e9 + 7;\n        vector<vector<int>> dp(n + 1, vector<int>(n + 1));\n        for (int j = 0; j <= n; j++){\n            dp[0][j] = 1;\n        } \n        for (int i = 0; i < n; i++){\n            if (S[i] == \'I\'){\n                for (int j = 0, cur = 0; j < n - i; j++)\n                    dp[i + 1][j] = cur = (cur + dp[i][j]) % mod;\n            } else {\n                for (int j = n - i - 1, cur = 0; j >= 0; j--)\n                    dp[i + 1][j] = cur = (cur + dp[i][j + 1]) % mod;   \n            }\n        }  \n        return dp[n][0];\n    }\n};\n```
[]