set<vector<int> > combinationSum(vector<int> &candi, int curPos, int target){
     set<vector<int> > ret;
     if( target <= 0 || curPos >= candi.size() )
         return ret;
     
     for( int i = curPos; i < candi.size(); i++ ){
         if( candi[i] > target )
             break;
         
         
         if( candi[i] == target ){
             vector<int> hit;
             hit.push_back(candi[i]);
             ret.insert(hit);
         }
         else{
             set<vector<int> > subSet = combinationSum(candi, i+1, target-candi[i]);   // the only difference with question 39!
             if( subSet.empty() )
                 continue;
             
             for( set<vector<int>>::iterator it = subSet.begin(); it != subSet.end(); ++it ){
                 vector<int> hit;
                 hit.push_back(candi[i]);
                 appendToVector(hit, *it);
                 ret.insert(hit);
             }
         }
     }
     
     return ret;
 }
Пример #2
0
void appendToVector(Vector<uint8_t> &dst, const uint8_t *data, size_t size)
{
    appendToVector(dst, static_cast<uint32_t>(size));
    dst.append(data, size);
}
Пример #3
0
void appendToVector(Vector<uint8_t> &dst, const String &src)
{
    appendToVector(dst, static_cast<uint32_t>(src.length()));
    dst.append(reinterpret_cast<const uint8_t *>(src.c_str()), src.length());
}
Пример #4
0
void appendToVector(Vector<uint8_t> &dst, const Vector<Ty> &src)
{
    appendToVector(dst, static_cast<uint32_t>(src.size()));
    dst.append(src);
}