Forming Quiz Teams dp + bitmasking Problem Link #include <iostream> #include <cstdio> #include <math.h> #include <cstring> #define sf(a) scanf("%d", &a) #define REP(i, n) for(int i = 0; i < n; i++) using namespace std; int n, posx, posy; char name[21]; double dist[17][17]; double dp[1 << 16]; int xy[17][2]; double solve(int bits) { if(dp[bits] != -1) return dp[bits]; if(bits == (1 << n) - 1) return 0; double ans = 1 << 30; // random big number for(int i = 0; i < n; i++) { if(!(bits & (1 << i))) { for(int j = i + 1; j < n; j++) { if(!(bits & (1 << j))) { ans = min(ans, solve(bits | (1 << i) | (1 << j)) +