You can use fundamental principal of counting, like incrementing the last digit till it reaches its max value, then increment the second last one and so on, like a countdown does
Here is a sample code, assuming there might be diff length of diff lists.
#include
using namespace std;
int main() {
int n;
cin>>n;
int a[n], len[n],i,j;
for(i = 0 ; i < n ; i++)
{
cin>>len[i];
a[i]=0;
}
while(1)
{
for(i = 0 ; i< n;i++)
cout<=0 ; j--)
{
if(++a[j]<=len[j])
break;
else
a[j]=0;
}
if(j<0)
break;
}
return 0;
}
Try to run the code with 4 1 1 1 1 and it will give all 4 digit permutations of 0 and 1.
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
You can use 2d arrays for getting combinations of nos.