NYOJ-组合数

题目网址:http://acm.nyist.net/JudgeOnline/problem.php?pid=32

代码类似以前做过的题。

 1 #include <stdio.h>
 2 #include <iostream>
 3 using namespace std;
 4 int n,r;
 5 int a[15];
 6 void dfs(int cur,int k){
 7     a[k] = cur;
 8     if(k + 1 == r){
 9         for(int i = 0; i < r; i++)
10             printf("%d",a[i]);
11         printf("
");
12         return ;
13     }
14     for(int i = cur - 1; i > 0; i--) dfs(i,k + 1);
15 }
16 int main(void){
17     while(scanf("%d%d",&n,&r) != EOF){
18         for(int i = n; i > 0; i--)
19             dfs(i,0);
20     }
21     return 0;
22 }
原文地址:https://www.cnblogs.com/yfs123456/p/5613411.html