当前位置:网站首页>HZOJ #235. Recursive implementation of exponential enumeration
HZOJ #235. Recursive implementation of exponential enumeration
2022-07-07 12:51:00 【Duange】
subject :235. Recursive implementation of exponential enumeration
Subject portal :235 topic
Title Description
from 1−n1−n this nn Randomly select any number of integers , The numbers in each scheme are arranged from small to large , Output all possible options in dictionary order .
Input
Enter an integer nn.(1≤n≤10)(1≤n≤10)
Output
Each line has a set of schemes , The two numbers in each group are separated by spaces .
Note that there is no space after the last number in each line .
sample input
3
Sample output
1
1 2
1 2 3
1 3
2
2 3
3
The sample input
4
Sample output
1
1 2
1 2 3
1 2 3 4
1 2 4
1 3
1 3 4
1 4
2
2 3
2 3 4
2 4
3
3 4
4
Code 1
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int n, num[15];
void print(int ind)
{
for (int i = 0; i <= ind; i++)
{
if (i) cout << " ";
cout << num[i];
}
cout << endl;
}
void func(int start, int ind)
{
for (int i = start; i <= n; i++)
{
num[ind] = i;
print(ind);
func(i + 1, ind + 1);
}
}
int main()
{
cin >> n;
func(1, 0);
return 0;
}
Code 2
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int n, num[15],cnt;
void print()
{
for (int i = 0; i <= cnt; i++)
{
if (i) cout << " ";
cout << num[i];
}
cout << endl;
}
void func(int start)
{
for (int i = start; i <= n; i++)
{
num[cnt] = i;
print();
cnt++;
func(i + 1);
cnt--;
}
}
int main()
{
cin >> n;
func(1);
return 0;
}
边栏推荐
- leetcode刷题:二叉树26(二叉搜索树中的插入操作)
- 在字符串中查找id值MySQL
- 图像像素读写操作
- Leetcode skimming: binary tree 21 (verifying binary search tree)
- [statistical learning method] learning notes - support vector machine (I)
- MPLS experiment
- What is an esp/msr partition and how to create an esp/msr partition
- ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
- Visual stdio 2017 about the environment configuration of opencv4.1
- GCC compilation error
猜你喜欢
2022 examination questions and online simulation examination for safety production management personnel of hazardous chemical production units
leetcode刷题:二叉树20(二叉搜索树中的搜索)
图形对象的创建与赋值
Vxlan static centralized gateway
Visual stdio 2017 about the environment configuration of opencv4.1
3D content generation based on nerf
Master formula. (used to calculate the time complexity of recursion.)
leetcode刷题:二叉树27(删除二叉搜索树中的节点)
On valuation model (II): PE index II - PE band
【统计学习方法】学习笔记——支持向量机(上)
随机推荐
HZOJ #240. 图形打印四
MySQL导入SQL文件及常用命令
[疑难杂症]pip运行突然出现ModuleNotFoundError: No module named ‘pip‘
谷歌浏览器如何重置?谷歌浏览器恢复默认设置?
What if the xshell evaluation period has expired
[pytorch practice] use pytorch to realize image style migration based on neural network
BGP actual network configuration
opencv的四个函数
2022A特种设备相关管理(锅炉压力容器压力管道)模拟考试题库模拟考试平台操作
【统计学习方法】学习笔记——支持向量机(下)
Leetcode question brushing: binary tree 26 (insertion operation in binary search tree)
Leetcode brush question: binary tree 24 (the nearest common ancestor of binary tree)
Configure an encrypted web server
【统计学习方法】学习笔记——支持向量机(上)
【统计学习方法】学习笔记——第五章:决策树
[statistical learning method] learning notes - support vector machine (I)
leetcode刷题:二叉树26(二叉搜索树中的插入操作)
非分区表转换成分区表以及注意事项
Routing strategy of multi-point republication [Huawei]
Steps of building SSM framework