C++ DFS + Comb
cpp\nint dp[1001][1001] = {};\nint comb(int n, int m) {\n    return n == 0 || m == 0 ? 1 :\n        dp[n][m] ? dp[n][m] : \n            dp[n][m] = (comb(n - 1, 
```cpp\nint dp[1001][1001] = {};\nint comb(int n, int m) {\n    return n == 0 || m == 0 ? 1 :\n        dp[n][m] ? dp[n][m] : \n            dp[n][m] = (comb(n - 1, m) + comb(n, m - 1)) % 1000000007;\n}\nlong dfs(vector<int>& n) {\n    if (n.size() <= 1)\n        return 1;\n    vector<int> n1, n2;\n    copy_if(begin(n), end(n), back_inserter(n1), [&] (int i) { return i < n.front(); });\n    copy_if(begin(n), end(n), back_inserter(n2), [&] (int i) { return i > n.front(); });\n    return dfs(n1) * dfs(n2) % 1000000007 * comb(n1.size(), n2.size()) % 1000000007;\n}\nint numOfWays(vector<int>& n) { return dfs(n) - 1; }\n```
[]