标签:
5 3
543 542 541 532 531 521 432 431 421 321
关键点
1.画出递归树,理清每次递归或每到一个节点时的判断条件
2.需要有两个全局变量记录递归路径和递归次数
#include<stdio.h> int str[5]; int count = 0; void output(int m, int n) { str[count] = m; count++; if(count == n+1) { for(int i = 1; i < count; i++) printf("%d", str[i]); printf("\n"); } else { while(m-- && m > 0) { output(m,n); } } count--; } int main() { int M,N; scanf("%d%d",&M,&N); output(M+1, N); return 1; }
标签:
原文地址:http://www.cnblogs.com/sdlwlxf/p/4569995.html