当前位置:网站首页>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;
}
边栏推荐
- Find ID value MySQL in string
- Leetcode skimming: binary tree 22 (minimum absolute difference of binary search tree)
- @What is the difference between resource and @autowired?
- Realize a simple version of array by yourself from
- Day-18 hash table, generic
- The URL modes supported by ThinkPHP include four common modes, pathinfo, rewrite and compatibility modes
- Decrypt gd32 MCU product family, how to choose the development board?
- Four functions of opencv
- Day-24 UDP, regular expression
- 广州市召开安全生产工作会议
猜你喜欢

Session
![[pytorch practice] image description -- let neural network read pictures and tell stories](/img/39/b2c61ae0668507f50426b01f2deee4.png)
[pytorch practice] image description -- let neural network read pictures and tell stories

leetcode刷题:二叉树19(合并二叉树)

【PyTorch实战】用RNN写诗

Day-19 IO stream

About IPSec

The left-hand side of an assignment expression may not be an optional property access. ts(2779)

【统计学习方法】学习笔记——逻辑斯谛回归和最大熵模型
![[pytorch practice] write poetry with RNN](/img/91/a6d3f348ff099b7c44eb185921b1b6.png)
[pytorch practice] write poetry with RNN

Experiment with a web server that configures its own content
随机推荐
2022 polymerization process test question simulation test question bank and online simulation test
Airserver automatically receives multi screen projection or cross device projection
【PyTorch实战】用RNN写诗
在字符串中查找id值MySQL
Leetcode skimming: binary tree 21 (verifying binary search tree)
Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment
2022-07-07 Daily: Ian Goodfellow, the inventor of Gan, officially joined deepmind
Master formula. (used to calculate the time complexity of recursion.)
opencv的四个函数
Leetcode skimming: binary tree 22 (minimum absolute difference of binary search tree)
Routing strategy of multi-point republication [Huawei]
Day-24 UDP, regular expression
leetcode刷题:二叉树19(合并二叉树)
[statistical learning methods] learning notes - Chapter 4: naive Bayesian method
Connect to blog method, overload, recursion
OSPF exercise Report
Steps of building SSM framework
mysql怎么创建,删除,查看索引?
谷歌浏览器如何重置?谷歌浏览器恢复默认设置?
处理链中断后如何继续/子链出错removed from scheduling