当前位置:网站首页>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;
}
边栏推荐
- 【从 0 开始学微服务】【00】课程概述
- [statistical learning method] learning notes - support vector machine (I)
- RHSA first day operation
- Niuke website
- Common knowledge of one-dimensional array and two-dimensional array
- About web content security policy directive some test cases specified through meta elements
- Cryptography series: detailed explanation of online certificate status protocol OCSP
- [deep learning] image multi label classification task, Baidu paddleclas
- HZOJ #235. 递归实现指数型枚举
- visual stdio 2017关于opencv4.1的环境配置
猜你喜欢

【PyTorch实战】用RNN写诗

Day-15 common APIs and exception mechanisms

leetcode刷题:二叉树24(二叉树的最近公共祖先)

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

leetcode刷题:二叉树23(二叉搜索树中的众数)

The hoisting of the upper cylinder of the steel containment of the world's first reactor "linglong-1" reactor building was successful

Vxlan 静态集中网关

Epp+dis learning path (1) -- Hello world!

What if does not match your user account appears when submitting the code?

【统计学习方法】学习笔记——逻辑斯谛回归和最大熵模型
随机推荐
【统计学习方法】学习笔记——逻辑斯谛回归和最大熵模型
ICLR 2022 | 基于对抗自注意力机制的预训练语言模型
SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
Solutions to cross domain problems
gcc 编译报错
Processing strategy of message queue message loss and repeated message sending
数据库安全的重要性
The IDM server response shows that you do not have permission to download the solution tutorial
Vxlan 静态集中网关
Inverted index of ES underlying principle
Attack and defense world ----- summary of web knowledge points
【统计学习方法】学习笔记——第五章:决策树
图形对象的创建与赋值
利用栈来实现二进制转化为十进制
Connect to blog method, overload, recursion
PHP调用纯真IP数据库返回具体地址
About IPSec
Realize all, race, allsettled and any of the simple version of promise by yourself
What if does not match your user account appears when submitting the code?
Typescript interface inheritance