Сортить Пушкин будет?)
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
vector<int> generator(int n, int m) {
vector <int> v;
for(int i=0; i<pow((double)2,n)-1; i++ ) {
if(i<=m-1) v.push_back(1);
else v.push_back(0);
}
return v;
}
int main()
{
int n,m;
cout<<"N:";
cin>>n;
cout<<"M:";
cin>>m;
vector<int> v = generator(n,m);
sort(v.begin(), v.end());
do
{
for(int i=0; i<v.size(); i++)
cout <<v[i]<<" ";
cout<<endl;
}
while(next_permutation(v.begin(), v.end()));
return 0;
}