标签:
5 3
543 542 541 532 531 521 432 431 421 321
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int n, r; int book[11],a[15]; void dfs(int step,int n, int r) { if(step == r) { for(int i = 0; i < r; i++) printf("%d",a[i]); printf("\n"); return; } for(int i = n; i > 0; i --) { if(book[i] == 0) { if(step == 0) a[step] = i; else if(i < a[step-1]) a[step] = i; else continue; book[i] = 1; dfs(step+1,n,r); book[i] = 0; printf("b"); } } } int main() { int n, r; memset(book,0,sizeof(book)); scanf("%d%d",&n,&r); dfs(0,n,r); return 0; }
标签:
原文地址:http://www.cnblogs.com/ekinzhang/p/4345170.html