// id 0-14 or 1-15 all nums chosed 5 groups
std::vector<uint8_t> candidates = {14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
std::vector<std::vector<uint8_t>> combines = Combine(candidates,5);
std::vector<std::vector<uint8_t>> GeoHash::Combine(std::vector<uint8_t> &combines,int size)
{
std::vector<std::vector<uint8_t>> ret;
if (combines.size() == size){
ret.push_back(combines);
return ret;
}
//out judge
if (1 == size){
for (auto &item : combines)
{
std::vector<uint8_t> vtTemp;
vtTemp.push_back(item);
ret.push_back(vtTemp);
}
return ret;
}
int i = 1;
for (auto it = combines.begin(); it != combines.end() && (combines.size() - i) >= (size - 1);it++, i++)
{
if (it + 1 != combines.end())
{
std::vector<uint8_t> vtBack(it + 1, combines.end());
std::vector<std::vector<uint8_t>> vtCombi1 = GeoHash::Combine(vtBack, size - 1);
for (auto &item : vtCombi1)
{
item.push_back(*it);
}
ret.insert(ret.end(), vtCombi1.begin(), vtCombi1.end());
}
}
return ret;
}
https://blog.csdn.net/tomwillow/article/details/81133932