当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

HZOJ #240. 图形打印四
![[pytorch practice] write poetry with RNN](/img/91/a6d3f348ff099b7c44eb185921b1b6.png)
[pytorch practice] write poetry with RNN

2022聚合工艺考试题模拟考试题库及在线模拟考试

ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics

【统计学习方法】学习笔记——提升方法

Leetcode question brushing: binary tree 26 (insertion operation in binary search tree)

JS to convert array to tree data

Leetcode skimming: binary tree 25 (the nearest common ancestor of binary search tree)

Leetcode brush question: binary tree 24 (the nearest common ancestor of binary tree)

Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment
随机推荐
opencv的四个函数
2022 practice questions and mock examination of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge)
[pytorch practice] image description -- let neural network read pictures and tell stories
3D content generation based on nerf
通讯协议设计与实现
mysql怎么创建,删除,查看索引?
Day-16 set
Talk about four cluster schemes of redis cache, and their advantages and disadvantages
【从 0 开始学微服务】【03】初探微服务架构
ip2long与long2IP 分析
Error in compiling libssl
Session
Image pixel read / write operation
利用栈来实现二进制转化为十进制
leetcode刷题:二叉树20(二叉搜索树中的搜索)
ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
[deep learning] image multi label classification task, Baidu paddleclas
聊聊Redis缓存4种集群方案、及优缺点对比
What is an esp/msr partition and how to create an esp/msr partition
[pytorch practice] use pytorch to realize image style migration based on neural network