<p>You are given a string <code>s</code> of length <code>n</code> where <code>s[i]</code> is either:</p>

<ul>
	<li><code>&#39;D&#39;</code> means decreasing, or</li>
	<li><code>&#39;I&#39;</code> means increasing.</li>
</ul>

<p>A permutation <code>perm</code> of <code>n + 1</code> integers of all the integers in the range <code>[0, n]</code> is called a <strong>valid permutation</strong> if for all valid <code>i</code>:</p>

<ul>
	<li>If <code>s[i] == &#39;D&#39;</code>, then <code>perm[i] &gt; perm[i + 1]</code>, and</li>
	<li>If <code>s[i] == &#39;I&#39;</code>, then <code>perm[i] &lt; perm[i + 1]</code>.</li>
</ul>

<p>Return <em>the number of <strong>valid permutations</strong> </em><code>perm</code>. Since the answer may be large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;DID&quot;
<strong>Output:</strong> 5
<strong>Explanation:</strong> The 5 valid permutations of (0, 1, 2, 3) are:
(1, 0, 3, 2)
(2, 0, 3, 1)
(2, 1, 3, 0)
(3, 0, 2, 1)
(3, 1, 2, 0)
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;D&quot;
<strong>Output:</strong> 1
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == s.length</code></li>
	<li><code>1 &lt;= n &lt;= 200</code></li>
	<li><code>s[i]</code> is either <code>&#39;I&#39;</code> or <code>&#39;D&#39;</code>.</li>
</ul>

class Solution {
public:
    int numPermsDISequence(string s) {
        const int MOD = 1e9 + 7; // Constant to hold the modulus value for large numbers
        int sequenceLength = s.size(); // The length of the sequence
        vector<int> dp(sequenceLength + 1, 0); // Dynamic programming table
        dp[0] = 1; // Base case initialization

        // Iterate over the characters in the input string
        for (int i = 1; i <= sequenceLength; ++i) {
            int accumulated = 0;
            vector<int> nextDP(sequenceLength + 1, 0); // Create a new DP array for the next iteration

            // Check if the current character is 'D' for a decreasing relationship
            if (s[i - 1] == 'D') {
                // Fill in the DP table backwards for 'D'
                for (int j = i; j >= 0; --j) {
                    accumulated = (accumulated + dp[j]) % MOD; // Update accumulated sum
                    nextDP[j] = accumulated; // Update the next DP table
                }
            } else {
                // Else, this is an increasing relationship represented by 'I'
                for (int j = 0; j <= i; ++j) {
                    nextDP[j] = accumulated; // Set the value for 'I'
                    accumulated = (accumulated + dp[j]) % MOD; // Update the accumulated sum
                }
            }
            dp = move(nextDP); // Move the next DP table into the current DP table for the next iteration
        }

        // Sum all possibilities from the last DP table to get the final answer
        int answer = 0;
        for (int j = 0; j <= sequenceLength; ++j) {
            answer = (answer + dp[j]) % MOD;
        }

        return answer; // Return the total number of permutations that match the DI sequence
    }
};
9000