当前位置:网站首页>HZOJ #236. 递归实现组合型枚举
HZOJ #236. 递归实现组合型枚举
2022-07-07 10:36:00 【段舸】
题目:236. 递归实现组合型枚举
题目传送门:236题
题目描述
从 1−n1−n 这 nn 个整数中随机选取 mm 个,每种方案里的数从小到大排列,按字典序输出所有可能的选择方案。
输入
输入两个整数 n,mn,m。(1≤m≤n≤10)(1≤m≤n≤10)
输出
每行一组方案,每组方案中两个数之间用空格分隔。
注意每行最后一个数后没有空格。
样例输入
3 2
样例输出
1 2
1 3
2 3
样例输入2
5 3
样例输出2
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5
代码
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int n, m, num[15];
void func(int start, int left, int ind)
{
if (left == 0)
{
for (int i = 0; i < m; i++)
{
if (i) cout << " ";
cout << num[i];
}
cout << endl;
return;
}
for (int i = start; i <= n; i++)
{
num[ind] = i;
func(i + 1, left - 1, ind + 1);
}
}
int main()
{
cin >> n >> m;
func(1, m, 0);
return 0;
}
边栏推荐
- 2022-07-07日报:GAN发明者Ian Goodfellow正式加入DeepMind
- Routing strategy of multi-point republication [Huawei]
- Solutions to cross domain problems
- Tutorial on the principle and application of database system (011) -- relational database
- ip2long之后有什么好处?
- Static routing assignment of network reachable and telent connections
- Cryptography series: detailed explanation of online certificate status protocol OCSP
- Decrypt gd32 MCU product family, how to choose the development board?
- "Series after reading" my God! It's so simple to understand throttling and anti shake~
- IPv6 experiment
猜你喜欢
Tutorial on principles and applications of database system (010) -- exercises of conceptual model and data model
Inverted index of ES underlying principle
Static comprehensive experiment
ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
AirServer自动接收多画面投屏或者跨设备投屏
[play RT thread] RT thread Studio - key control motor forward and reverse rotation, buzzer
Aike AI frontier promotion (7.7)
Learning and using vscode
[statistical learning method] learning notes - support vector machine (I)
【PyTorch实战】用RNN写诗
随机推荐
leetcode刷题:二叉树27(删除二叉搜索树中的节点)
SQL lab 21~25 summary (subsequent continuous update) (including secondary injection explanation)
【从 0 开始学微服务】【03】初探微服务架构
浅谈估值模型 (二): PE指标II——PE Band
In the small skin panel, use CMD to enter the MySQL command, including the MySQL error unknown variable 'secure_ file_ Priv 'solution (super detailed)
test
【深度学习】图像多标签分类任务,百度PaddleClas
visual stdio 2017关于opencv4.1的环境配置
IPv6 experiment
Cookie
[疑难杂症]pip运行突然出现ModuleNotFoundError: No module named ‘pip‘
Is it safe to open an account in Ping An Securities mobile bank?
Multi row and multi column flex layout
sql-lab (54-65)
On valuation model (II): PE index II - PE band
Utiliser la pile pour convertir le binaire en décimal
[statistical learning methods] learning notes - Chapter 5: Decision Tree
[pytorch practice] use pytorch to realize image style migration based on neural network
[statistical learning method] learning notes - support vector machine (I)
Day-20 file operation, recursive copy, serialization