B. 组合数

来源:互联网 发布:ios内购 元数据丢失 编辑:程序博客网 时间:2024/06/03 18:39

B. 组合数

Time Limit: 3000ms
Memory Limit: 128000KB
64-bit integer IO format:      Java class name:
SubmitStatusPID: 4644
找出从自然数1、2、... 、n(0<n<10)中任取r(0<r<=n)个数的所有组合。

Input

输入n、r。

Output

按特定顺序输出所有组合。
特定顺序:每一个组合中的值从大到小排列,组合之间按逆字典序排列。

Sample Input

5 3

Sample Output

543
542
541
532
531
521
432
431
421
321
#include <stdio.h>int a[10];void DFS(int n,int r){for(int i = n; i > 0; i--){a[r] = i;if(r > 1){DFS(i-1,r-1);}else{for(int i = a[0]; i > 0; i--){printf("%d",a[i]);}printf("\n");}}}int main(){int n,r;scanf("%d%d",&n,&r);a[0] = r;DFS(n,r);return 0;}

0 0
原创粉丝点击