#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, m;
char *buf;
int token, index, cnt, first;
scanf("%d %d", &n, &m);
buf = (char *)malloc(n + 1);
memset(buf, 0x00, n + 1 );
memset(buf, 0x01, m);
buf[n] = 1;
while (1)
{
first = -1;
token = 0;
//输出
for (index=0, cnt=0; index < n; index ++)
{
if (buf[index])
{
if (first < 0 && !buf[index + 1])
{
first = index; //记录第一个'10'的位置
token = cnt; //记录第一个'10'前面1的个数
}
cnt ++;
printf("%d ", index + 1);
if (cnt == m)
{
break;
}
}
}
printf("\n");
//结束
if(first < 0)
{
break;
}
//翻转并移位
buf[first] = 0x00;
buf[first + 1] = 0x01;
memset(buf, 0x00, first); //将第一个'10'前面的1全部置0
memset(buf, 0x01, token); //置cnt个1
}
}
|