当前位置:网站首页>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;
}
边栏推荐
- SSM框架搭建的步骤
- 【统计学习方法】学习笔记——第四章:朴素贝叶斯法
- Routing strategy of multi-point republication [Huawei]
- Day-15 common APIs and exception mechanisms
- opencv的四个函数
- Day-19 IO stream
- 《ASP.NET Core 6框架揭秘》样章[200页/5章]
- 聊聊Redis缓存4种集群方案、及优缺点对比
- [pytorch practice] image description -- let neural network read pictures and tell stories
- Aike AI frontier promotion (7.7)
猜你喜欢
How to apply @transactional transaction annotation to perfection?
【PyTorch实战】用PyTorch实现基于神经网络的图像风格迁移
ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
JS to convert array to tree data
Day22 deadlock, thread communication, singleton mode
Configure an encrypted web server
leetcode刷题:二叉树20(二叉搜索树中的搜索)
leetcode刷题:二叉树19(合并二叉树)
Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment
opencv的四个函数
随机推荐
Connect to blog method, overload, recursion
详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
[statistical learning methods] learning notes - improvement methods
xshell评估期已过怎么办
What if the xshell evaluation period has expired
ICLR 2022 | pre training language model based on anti self attention mechanism
2022聚合工艺考试题模拟考试题库及在线模拟考试
leetcode刷题:二叉树24(二叉树的最近公共祖先)
Common knowledge of one-dimensional array and two-dimensional array
[Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
Session
MySQL导入SQL文件及常用命令
【PyTorch实战】图像描述——让神经网络看图讲故事
Routing strategy of multi-point republication [Huawei]
Several ways to clear floating
Leetcode skimming: binary tree 21 (verifying binary search tree)
Day-14 common APIs
leetcode刷题:二叉树26(二叉搜索树中的插入操作)
OSPF exercise Report
[crawler] avoid script detection when using selenium