当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Dialogue with Wang Wenyu, co-founder of ppio: integrate edge computing resources and explore more audio and video service scenarios
[statistical learning methods] learning notes - improvement methods
How to use PS link layer and shortcut keys, and how to do PS layer link
How to apply @transactional transaction annotation to perfection?
[statistical learning methods] learning notes - Chapter 5: Decision Tree
处理链中断后如何继续/子链出错removed from scheduling
明星企业普渡科技大裁员:曾募资超10亿 腾讯红杉是股东
Connect to blog method, overload, recursion
[statistical learning method] learning notes - support vector machine (Part 2)
Day-14 common APIs
随机推荐
BGP third experiment report
Object. Simple implementation of assign()
Sorting, dichotomy
What if does not match your user account appears when submitting the code?
【从 0 开始学微服务】【02】从单体应用走向服务化
Simple implementation of call, bind and apply
[Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
Day-20 file operation, recursive copy, serialization
leetcode刷题:二叉树21(验证二叉搜索树)
Cookie
Minimalist movie website
ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
@Resource和@Autowired的区别?
What is an esp/msr partition and how to create an esp/msr partition
[crawler] avoid script detection when using selenium
Dialogue with Wang Wenyu, co-founder of ppio: integrate edge computing resources and explore more audio and video service scenarios
非分区表转换成分区表以及注意事项
在字符串中查找id值MySQL
【从 0 开始学微服务】【00】课程概述
Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment