title: count all subsets of given array with sum equal to given sum
body: <h2>what can i do to optimize this code,if language will be c++ it will be more easy for me to understand.</h2>
  
  <p>Given an array of integers and a sum, the task is to count all  subsets of given array with sum equal to given sum.
  Input : arr[] = {2, 3, 5, 6, 8, 10}, sum = 10,subsets are -> {5 2 3},
           {2 8},
           {10}, Output : 3 Input : arr[] = {1, 2, 3, 4, 5}, sum = 10, subsets are -> {4 3 2 1}, 
           {5 3 2 },
           {5 4 1},  Output : 3) </p>
  
  <hr>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  
  using namespace std;
  
  
  string binary_string(int i,int len){
  
      string res="";
      int mod =0;
  
          while(i&gt;0){
          mod = i%2;
          res+=to_string(mod);
          i/=2;
      }
  
      int n = res.length();
  
      if(n!=len){
          while(n!=len){
              res.append("0");
              n++;
  
          }
  
  
           return res;
      }
  
  
  
      return res;
  }
  
  int main()
  {
     int t;
     cin&gt;&gt;t;
  
     while(t--){
      string binary;//,subseq;
      int n,k,count=0,sum,val;
      cin&gt;&gt;n;
  
      vector&lt;int&gt;vect;
  
      for(int i=0;i&lt;n;i++){
          cin&gt;&gt;k;
          vect.push_back(k);
      }
      cin&gt;&gt;val;
  
  
      int bits_range = (int)pow(2,n) - 1;
  
  
  
      //cout&lt;&lt;"SUBSETS ARE :"&lt;&lt;endl;
      for(int i=0;i&lt;=bits_range;i++){
          binary=binary_string(i,n);
          sum=0;
          for(int i=binary.length()-1;i&gt;=0;i--){
              if(binary[i]=='1'){
                  //subseq+=to_string(vect[i]);
                  sum+=vect[i];
  
              }
  
          }
          if(sum==val){
              count++;
              //cout&lt;&lt;subseq&lt;&lt;endl;
              //subseq="";
          }
          //subseq="";
      }
  
          cout&lt;&lt;count&lt;&lt;endl;
     }
  
  
  
  }
  </code></pre>