[Cpp]
/*************************************** *****************\
Class cyclic arrangement problems such:
Input: 2 3
Output:
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
/*************************************** *****************/
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include <assert. h>
Const int maxn = 100;
Int ans [maxn];
Void output (int m)
{
For (int I = 0; I <m; I ++)
{
If (I <s-1)
Printf ("% d", ans [I]);
Else
Printf ("% d \ n", ans [I]);
}
}
/* N: The Element range is from 0 ~ N-1 m: m-bit total */
Void loopPerm (int n, int m, int dep)
{
If (dep> = m)/* if the recursive depth is greater than m, it indicates that there is already an m-bit arrangement */
{
Output (dep );
Return;
}
For (int I = 0; I <n; I ++)/* Each bit has n types of data */
{
Ans [dep] = I;
Dep + = 1;
LoopPerm (n, m, dep);/* select the next position */
Dep-= 1;
}
}
Void test ()
{
Int n = 0, m = 0;
While (scanf ("% d", & n, & m )! = EOF)
{
If (n = 0) break;
Memset (ans,-1, sizeof (ans ));
LoopPerm (n, m, 0 );
}
}
Int main ()
{
Test ();
Return 0;
}