web::json::value multiplayer_session_request::create_role_types_json() { web::json::value serializedObject; if (m_roleTypes.size() > 0) { web::json::value roleTypeJson; for (const auto& roleType : m_roleTypes) { web::json::value rolesJson; auto roles = roleType.second.roles(); for (const auto& role : roles) { web::json::value roleJson; auto roleInfo = role.second; if (roleInfo.max_members_count() > 0) { roleJson[_T("max")] = roleInfo.max_members_count(); } if (roleInfo.target_count() > 0) { roleJson[_T("target")] = roleInfo.target_count(); } rolesJson[role.first] = roleJson; } roleTypeJson[_T("roles")] = rolesJson; serializedObject[roleType.first] = roleTypeJson; } } return serializedObject; }
int minStickersHelper(const vector<vector<int>>& sticker_counts, const string& target, unordered_map<string, int> *dp) { if (dp->count(target)) { return (*dp)[target]; } int result = numeric_limits<int>::max(); vector<int> target_count(26); for (const auto& c : target) { ++target_count[c - 'a']; } for (const auto& sticker_count : sticker_counts) { if (sticker_count[target[0] - 'a'] == 0) { continue; } string new_target; for (int i = 0; i < target_count.size(); ++i) { if (target_count[i] - sticker_count[i] > 0) { new_target += string(target_count[i] - sticker_count[i], 'a' + i); } } if (new_target.length() != target.length()) { int num = minStickersHelper(sticker_counts, new_target, dp); if (num != -1) { result = min(result, 1 + num); } } } (*dp)[target] = (result == numeric_limits<int>::max()) ? -1 : result; return (*dp)[target]; }