AcWing 93. 递归实现组合型枚举
原题链接
简单
作者:
nq
,
2021-02-20 21:27:27
,
所有人可见
,
阅读 247
递归
java 代码
import java.util.Scanner;
public class Main{
static int N = 25;
static int[] path = new int[N];
static int n,k;
public static void dfs(int k,int s,int l){
if(k == 0) {
for(int i = l - 1 ; i >= 0 ;i --) System.out.print(path[i]+" ");
System.out.println();
return;
}
for(int i = s; i <= n; i++){
path[k - 1] = i;
dfs(k - 1, i + 1, l);
}
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
n = in.nextInt();
k = in.nextInt();
dfs(k,1,k);
}
}