Count all unique subsets with Sum S Team 7 faces a horrible foe. He can only be defeated with a special
  quadruple combination attack of strength (\$1 &lt;=S &lt;= 10^9\$). Naruto,
  Sasuke, Sakura and Kakashi must attack simultaneously to perform the
  combo. Each of them can choose from \$N\$ (\$1 &lt;= N &lt;=1000\$) attacks,
  having strengths \$si\$ each (\$0 &lt;= i &lt; N\$, \$1 &lt;= si &lt;=10^9\$). The strengths
  of individual attacks add up to form the strength of the combo.
  
  Is there a valid combination that they can use? Note that the same attacks are available to all of them.
  
  You are required to write a function which takes input as follows:
  
  An integer \$N\$ as number of attacks, an integer vector s[] as the
  strengths of \$N\$ attacks and an integer S as the required strength of
  the combo. Set the output variable to the number of distinct valid
  combos.
  
  Two combinations are different if they differ in strength of at least one attack used.
  
  Input: 1 {1} 4
  Output: 1  ===> {1,1,1,1}
  
  Input: 2 {1,2} 5
  Output: 1 ===> {1,1,1,2}


#include "stdafx.h"
#include&lt;stdio.h&gt;
#include&lt;string.h&gt;
#include&lt;iostream&gt;
#include&lt;vector&gt;
#include&lt;map&gt;
#include&lt;set&gt;
#include&lt;algorithm&gt;

const int noOfPalyers = 4;

int validCombo(int input1,int input2[],int input3)
{
    std::cout&lt;&lt; "-----------------------------------------------------------------------------"&lt;&lt;"\n";
    int count = 0;
    std::vector&lt;int&gt; vec;
    int size =input1*noOfPalyers;
    for(int i = 0; i &lt; input1; i++)
    {
        for(int j = 0; j &lt; noOfPalyers;j++)
        {
            vec.push_back(input2[i]);
        }
    }

    std::vector&lt; std::vector&lt; std::pair&lt;int, int&gt; &gt; &gt; vecHash;

    for(int i =0; i &lt; (size*size); i++)
    {
        vecHash.push_back(std::vector&lt; std::pair&lt;int, int&gt; &gt; ());
    }

    for(int i =0; i &lt; size; i++)
    {
        for(int j =1; j &lt; size; j++)

        {
            int key = vec[i] + vec[j];
            if(vec[i]&lt;= vec[j])
                vecHash[key].push_back(std::make_pair(vec[i], vec[j]));
            else
                vecHash[key].push_back(std::make_pair(vec[j], vec[i]));

        }
    }

    std::set&lt; std::vector&lt;int&gt; &gt; solution;
    for(int i = 0; i &lt; input3; i++)
    {

        if(vecHash[input3 - i].size() &gt; 0)
        {
            for(int k = 0; k &lt; vecHash[i].size() ; k++)
            {
                std::pair&lt;int, int&gt; fPair = vecHash[i][k];

                for(int m =0; m &lt; vecHash[input3 - i].size(); m++)
                {
                    std::pair&lt;int, int&gt; sPair = vecHash[input3 - i][m];
                    std::vector&lt;int&gt; vec;
                    vec.push_back(fPair.first);
                    vec.push_back(fPair.second);
                    vec.push_back(sPair.first);
                    vec.push_back(sPair.second);
                    std::sort(vec.begin(), vec.end());
                    solution.insert(vec);
                }

            }
        }
    }


    std::set&lt; std::vector&lt; int&gt; &gt;::iterator it;
    for (it = solution.begin(); it != solution.end(); it++) 
    {
        std::cout&lt;&lt; "\n";
        for(int i = 0; i &lt; (*it).size(); i++) 
            std::cout &lt;&lt; (*it)[i] &lt;&lt; " , ";
        std::cout&lt;&lt; "\n";
    }
    count = solution.size();


    std::cout &lt;&lt; "solution size = "  &lt;&lt; solutionSet.size();
    std::cout&lt;&lt; "\n";
    std::cout&lt;&lt; "\n";

    std::cout&lt;&lt; "-----------------------------------------------------------------------------"&lt;&lt;"\n";

    return count;

}

int  main()
{
    int i = 3;
    int arr[] = {1,2,3};
    int j = 7;
    int arr1[] ={1};
    std::cout &lt;&lt;"o/p == "  &lt;&lt; validCombo(i, arr, j)&lt;&lt; "\n";
    std::cout &lt;&lt;"o/p == "  &lt;&lt; validCombo(1, arr1, 4);


    getchar();
    return 0;
}
A lot of your vector initialization can be handled by vector's constructor. Not only is that much shorter and less error prone, it's also more efficient since it lets the vector avoid resizing over and over again.

As an example:

std::vector&lt; std::vector&lt; std::pair&lt;int, int&gt; &gt; &gt; vecHash;

for(int i =0; i &lt; (size*size); i++)
{
    vecHash.push_back(std::vector&lt; std::pair&lt;int, int&gt; &gt; ());
}


This can be:

std::vector&lt; std::vector&lt; std::pair&lt;int, int&gt; &gt; &gt; vecHash(size*size);




if(vecHash[input3 - i].size() &gt; 0)


This should be if(!vecHash[input3 - i].empty()) as empty() reads clearer.



Your logic and your IO should be handled separately. You should add a function for printing solutions so your validCombo isn't doing quite so much. That will mean returning the solutions instead of the number of solutions, but that makes more sense anyway.

For small little programs like this it doesn't really matter, but for anything non-trivial, you want each function to only do one thing. That allows you to control and modify things in a much easier way. (Even though we're not talking about OOP, this is essentially the essence of the SRP.



count = solution.size();
std::cout &lt;&lt; "solution size = "  &lt;&lt; solutionSet.size();

// ...

return count;


Either use count consistently, or don't bother assigning it.

Also, declare variables as close to use as possible. It's confusing to try to figure out where in the world count came from when it's declared a few dozen lines up.