[ C++ ] [ Dynamic Programming + DFS ]
Code\n\nclass Solution {\n    int mod = 1e9 + 7;\n    int combination(int k, int n, int mod) {\n        if (k > n - k) k = n - k;\n        vector<int> dp(k + 1)
# Code\n```\nclass Solution {\n    int mod = 1e9 + 7;\n    int combination(int k, int n, int mod) {\n        if (k > n - k) k = n - k;\n        vector<int> dp(k + 1);\n        dp[0] = 1;\n        for (int i = 1; i <= n; ++i) {\n            for (int j = min(i, k); j > 0; --j) dp[j] = (dp[j] + dp[j - 1]) % mod;\n        }\n        return dp[k];\n    }\n    int dfs(vector<int> &A)  {\n        if (A.size() <= 1) return 1;\n        int root = A[0];\n        vector<int> left, right;\n        for (int i = 1; i < A.size(); ++i) {\n            if (A[i] < root) left.push_back(A[i]);\n            else right.push_back(A[i]);\n        }\n        return ((long)combination(left.size(), A.size() - 1, mod) * dfs(left)) % mod * dfs(right) % mod;\n    }\npublic:\n    int numOfWays(vector<int>& A) {\n        return (dfs(A) - 1 + mod) % mod;\n    }\n};\n```
['C++']