当前位置:网站首页>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;
}
边栏推荐
- 编译 libssl 报错
- 爱可可AI前沿推介(7.7)
- ps链接图层的使用方法和快捷键,ps图层链接怎么做的
- NPM instal reports agent or network problems
- Attack and defense world - PWN learning notes
- Niuke website
- Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment
- Epp+dis learning road (2) -- blink! twinkle!
- Preorder, inorder and postorder traversal of binary tree
- Dialogue with Wang Wenyu, co-founder of ppio: integrate edge computing resources and explore more audio and video service scenarios
猜你喜欢

Attack and defense world ----- summary of web knowledge points

对话PPIO联合创始人王闻宇:整合边缘算力资源,开拓更多音视频服务场景
![[statistical learning methods] learning notes - improvement methods](/img/c5/515f171995da8e424de290228b54f8.png)
[statistical learning methods] learning notes - improvement methods

解决 Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually

Learning and using vscode

Charles: four ways to modify the input parameters or return results of the interface

SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)

Processing strategy of message queue message loss and repeated message sending

【PyTorch实战】用RNN写诗

opencv的四个函数
随机推荐
2022聚合工艺考试题模拟考试题库及在线模拟考试
【统计学习方法】学习笔记——支持向量机(下)
爱可可AI前沿推介(7.7)
Idea 2021 Chinese garbled code
test
如何将 @Transactional 事务注解运用到炉火纯青?
IPv6 experiment
Experiment with a web server that configures its own content
Customize the web service configuration file
【统计学习方法】学习笔记——支持向量机(上)
[爬虫]使用selenium时,躲避脚本检测
Day-15 common APIs and exception mechanisms
Vxlan 静态集中网关
Day-18 hash table, generic
Attack and defense world - PWN learning notes
Typescript interface inheritance
NGUI-UILabel
Sort out the garbage collection of JVM, and don't involve high-quality things such as performance tuning for the time being
Charles: four ways to modify the input parameters or return results of the interface
用mysql查询某字段是否有索引