92. 递归实现指数型枚举(Acwing)-递归
2021-03-07 16:27
标签:exti https class 代码 rgs main scanner string 实现 题目链接: https://www.acwing.com/problem/content/94/ 题解: 一个位置选或者不选两种情况,递归到边界(n个已经选完了),输出结果即可 AC代码: 92. 递归实现指数型枚举(Acwing)-递归 标签:exti https class 代码 rgs main scanner string 实现 原文地址:https://www.cnblogs.com/doubest/p/12820338.html92. 递归实现指数型枚举(Acwing)
import java.util.Scanner;
public class NO92 {
static int n;
static int N = 18;
static int[] visit = new int[N];
static void choose(int pos) {
if (pos >= n + 1) {
for (int i = 1;i 0) {
System.out.print(i + " ");
}
}
System.out.println();
return;
}
visit[pos] = 1;
choose(pos+1);
visit[pos] = 0;
choose(pos+1);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
choose(1);
}
}
下一篇:C#枚举
文章标题:92. 递归实现指数型枚举(Acwing)-递归
文章链接:http://soscw.com/index.php/essay/61411.html