5 3
543 542 541 532 531 521 432 431 421 321
#include<stdio.h>
#include<string.h>
int a[20],b[20];
int n,m;
void dfs(int cur,int pos)
{
int i;
if(pos==m+1)
{
for(i=1;i<=m;i++)
printf("%d",b[i]);
printf("\n");
return ;
}
if(cur>n) return ;
b[pos]=a[cur];
dfs(cur+1,pos+1);
dfs(cur+1,pos);
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=n,j=0;i>=1;i--)
a[++j]=i;
dfs(1,1);
}
return 0;
}
原文:http://www.cnblogs.com/tonghao/p/4709108.html