当前位置:网站首页>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;
}
边栏推荐
- MySQL importing SQL files and common commands
- 谷歌浏览器如何重置?谷歌浏览器恢复默认设置?
- The IDM server response shows that you do not have permission to download the solution tutorial
- Error in compiling libssl
- test
- HZOJ #236. Recursive implementation of combinatorial enumeration
- Using stack to convert binary to decimal
- The left-hand side of an assignment expression may not be an optional property access. ts(2779)
- HZOJ #236. 递归实现组合型枚举
- BGP third experiment report
猜你喜欢
Leetcode skimming: binary tree 23 (mode in binary search tree)
[pytorch practice] write poetry with RNN
visual stdio 2017关于opencv4.1的环境配置
HZOJ #240. 图形打印四
【统计学习方法】学习笔记——支持向量机(上)
On valuation model (II): PE index II - PE band
Cookie
[crawler] avoid script detection when using selenium
BGP actual network configuration
图形对象的创建与赋值
随机推荐
Talk about four cluster schemes of redis cache, and their advantages and disadvantages
test
Configure an encrypted web server
What if does not match your user account appears when submitting the code?
NPM instal reports agent or network problems
What if the xshell evaluation period has expired
Cookie
About IPSec
【从 0 开始学微服务】【02】从单体应用走向服务化
Day-19 IO stream
2022聚合工艺考试题模拟考试题库及在线模拟考试
Leetcode skimming: binary tree 23 (mode in binary search tree)
OSPF exercise Report
[learn microservice from 0] [01] what is microservice
基于NeRF的三维内容生成
Utiliser la pile pour convertir le binaire en décimal
2022 practice questions and mock examination of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge)
【从 0 开始学微服务】【00】课程概述
[learn microservices from 0] [03] explore the microservice architecture
[statistical learning method] learning notes - logistic regression and maximum entropy model