Java
\npublic int numPermsDISequence(String S) {\n        int n = S.length(), mod = (int)1e9 + 7;\n        int[][] dp = new int[n + 1][n + 1];\n        for (int j = 
```\npublic int numPermsDISequence(String S) {\n        int n = S.length(), mod = (int)1e9 + 7;\n        int[][] dp = new int[n + 1][n + 1];\n        for (int j = 0; j <= n; j++) dp[0][j] = 1;\n        for (int i = 0; i < n; i++)\n            if (S.charAt(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        return dp[n][0];\n    }\n```
[]