当前位置:网站首页>Acwing 92. recursive implementation of exponential enumeration
Acwing 92. recursive implementation of exponential enumeration
2022-07-24 12:04:00 【WDLieqi】
from 1∼n this n Randomly select any number of integers , Output all possible options .
Input format
Enter an integer n.
Output format
Output one solution per line .
The numbers in the same row must be in ascending order , Two adjacent numbers are used exactly 1 Space between .
For a scheme without any number of options , Output blank lines .
This question has a custom calibrator (SPJ), All walks of life ( Different options ) In any order .
Data range
1 ≤ n ≤ 15
sample input :
3
sample output :
// Blank line
3
2
2 3
1
1 3
1 2
1 2 3
Ideas
We can divide each node into selected and unselected , Just walk for the last time .
#include <iostream>
using namespace std;
const int N = 20;
int n;
bool vis[N]; // Decide whether to choose or not
void dfs(int u) // The first level is to filter the number
{
if (u > n) // You can't have an equal sign , If there is an equal sign, there will be less recursion , That is, the last layer cannot be recursive
{
for (int i = 1; i <= n; i ++) // from 1 To n choice
if (vis[i]) cout << i << ' ';
cout << '\n';
return;
}
else
{
vis[u] = true; // Choose this number
dfs(u + 1);
vis[u] = false; // Don't choose this number
dfs(u + 1);
}
}
int main()
{
cin >> n;
dfs(1); // from 1 Start choosing , To n end , So we can't go from 0 Start ;
return 0;
}
边栏推荐
- GCC的基本用法
- 理解数据的存与取
- Jackson parsing JSON detailed tutorial
- js图像转base64
- Skillfully using command line parameters in Delphi to realize the trigger function of dragging files onto program icons
- Two important laws about parallelism
- 6k+ star, a deep learning code base for Xiaobai! One line of code implements all attention mechanisms!
- SQL multi condition query cannot be implemented
- Share the typora tool
- Easy to use example
猜你喜欢

三、MFC消息映射机制实现原理

The art of management - driving software R & D efficiency through leadership

6k+ star, a deep learning code base for Xiaobai! One line of code implements all attention mechanisms!

Convergence rules for 4 * 4 image weights

6k+ star,面向小白的深度学习代码库!一行代码实现所有Attention机制!
![[rust] rust language foundation | you should quickly get an impression when learning a language](/img/70/b420d62759f0c52bf4cc8d2a500813.png)
[rust] rust language foundation | you should quickly get an impression when learning a language

三层交换机配置MSTP协议详解【华为eNSP实验】
![MOS tube - Notes on rapid recovery application (I) [principle]](/img/a1/8427c9b1d0ea0cecce820816510045.png)
MOS tube - Notes on rapid recovery application (I) [principle]
![[rust] what software should I use to develop rust? Recommended editors commonly used to support rust](/img/a8/becbf7dc059939120a6bc632fe8708.png)
[rust] what software should I use to develop rust? Recommended editors commonly used to support rust

JMeter while controller
随机推荐
Oracle 11.2.0.4 ASM single instance does not start automatically with system startup
Using huggingface model to translate English
Types and history of bugs in it circle
In kuborad graphical interface, operate kubernetes cluster to realize master-slave replication in MySQL
QT | summary of the use of edit box
[mathematical basis of Cyberspace Security Chapter 3] congruence
Hash - 242. valid alphabetic ectopic words
1184. 公交站间的距离 : 简单模拟题
Script redis write project notes
Learning materials about red team
Miss waiting for a year! Baidu super chain digital publishing service is limited to 50% discount
Shengxin weekly issue 37
哈希——202. 快乐数
VMware virtual machine and vSphere migrate to each other
Dry goods sharing - taking over a new data team as a lead - Problem Inventory and insights findings
Remember to optimize my personal blog once
Delphi gexperts expert instructions for improving development efficiency
[mathematical basis of Cyberspace Security Chapter 9] finite field
Day3: branch structure
Chapter 0 Introduction and environment configuration