Easy cpp, iterating through submasks O(3 ^ n)
```\nclass Solution {\npublic:\n    int minimumIncompatibility(vector& a, int k) {\n        int n = (int) a.size();\n        vector  cost(1 << n, 1e5);\n       
```\nclass Solution {\npublic:\n    int minimumIncompatibility(vector<int>& a, int k) {\n        int n = (int) a.size();\n        vector <int> cost(1 << n, 1e5);\n        vector <int> dp(1 << n, 1e8);\n        k = n / k;\n        for (int mask = 0; mask < (1 << n); ++mask) {\n            if (__builtin_popcount(mask) != k) continue;\n            set <int> now;\n            for (int i = 0; i < n; ++i) {\n                if ((mask >> i) & 1) now.insert(a[i]);\n            }\n            if ((int) now.size() != k) continue;\n            cost[mask] = (*now.rbegin()) - (*now.begin());\n            //dp[mask] = cost[mask];\n        }\n        dp[0] = 0;\n        for (int mask = 0; mask < (1 << n); ++mask) {\n            int mask2 = ((1 << n) - 1) ^ mask;\n            for (int sub = mask2; sub; sub = (sub - 1) & mask2) {\n                if (__builtin_popcount(sub) != k) continue;\n                dp[mask ^ sub] = min(dp[mask ^ sub], dp[mask] + cost[sub]);\n            }\n        }\n        if (dp[(1 << n) - 1] > 1e4) return -1;\n        return dp[(1 << n) - 1];\n    }\n};
['Dynamic Programming', 'Bitmask']