C++ DP dfs
```cpp []
class Solution {
public:
    long long m = 1e9 + 7;
    vector<vector<long long>> dp;
    int comb(int numRemaining, int numToChoose){
        if (numRemaining == 0 || numToChoose == 0) return 1;
        if (dp[numRemaining][numToChoose] == -1){
            long long s = 0;
            s += comb(numRemaining - 1, numToChoose - 1);
            s %= m;
            s += comb(numRemaining - 1, numToChoose);
            s %= m;
            dp[numRemaining][numToChoose] = s;
        }
        return dp[numRemaining][numToChoose];
    }
    int minMaxSums(vector<int>& nums, int k) {
        long long ans = 0;
        dp.resize(nums.size() + 1, vector<long long>(k + 1, -1));
        vector<long long> v;
        for (auto& n : nums) v.push_back(n);
        sort(v.begin(), v.end());
        for (int i = 0; i < nums.size(); ++i){
            ans += v[i] * (comb(nums.size() - i - 1, k - 1));
            ans %= m;
        }
        for (int i = nums.size() - 1; i >= 0; --i){
            ans += v[i] * (comb(i, k - 1));
            ans %= m;
        }
        return ans;
    }
};
```
['C++']