当前位置:网站首页>HZOJ #236. Recursive implementation of combinatorial enumeration
HZOJ #236. Recursive implementation of combinatorial enumeration
2022-07-07 12:50:00 【Duange】
subject :236. Recursive implementation of combinatorial enumeration
Subject portal :236 topic
Title Description
from 1−n1−n this nn Random selection of integers mm individual , The numbers in each scheme are arranged from small to large , Output all possible options in dictionary order .
Input
Enter two integers n,mn,m.(1≤m≤n≤10)(1≤m≤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 .
The sample input
3 2
Sample output
1 2
1 3
2 3
The sample input 2
5 3
Sample output 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
Code
#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;
}
边栏推荐
- PHP调用纯真IP数据库返回具体地址
- Simple implementation of call, bind and apply
- leetcode刷题:二叉树26(二叉搜索树中的插入操作)
- 【PyTorch实战】图像描述——让神经网络看图讲故事
- [learn wechat from 0] [00] Course Overview
- [learn microservice from 0] [01] what is microservice
- [statistical learning method] learning notes - support vector machine (I)
- Leetcode brush questions: binary tree 19 (merge binary tree)
- The left-hand side of an assignment expression may not be an optional property access. ts(2779)
- leetcode刷题:二叉树24(二叉树的最近公共祖先)
猜你喜欢
ps链接图层的使用方法和快捷键,ps图层链接怎么做的
What is an esp/msr partition and how to create an esp/msr partition
Leetcode question brushing: binary tree 26 (insertion operation in binary search tree)
什么是ESP/MSR 分区,如何建立ESP/MSR 分区
Leetcode brush questions: binary tree 19 (merge binary tree)
处理链中断后如何继续/子链出错removed from scheduling
Vxlan 静态集中网关
Several ways to clear floating
OSPF exercise Report
图形对象的创建与赋值
随机推荐
OSPF exercise Report
layer弹出层的关闭问题
xshell评估期已过怎么办
JS to convert array to tree data
Day-18 hash table, generic
ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
有什么类方法或是函数可以查看某个项目的Laravel版本的?
免费手机号码归属地API查询接口
Zhimei creative website exercise
2022A特种设备相关管理(锅炉压力容器压力管道)模拟考试题库模拟考试平台操作
Four functions of opencv
[binary tree] delete points to form a forest
Polymorphism, final, etc
Realize all, race, allsettled and any of the simple version of promise by yourself
Design and implementation of communication protocol
【统计学习方法】学习笔记——提升方法
Leetcode skimming: binary tree 23 (mode in binary search tree)
Common knowledge of one-dimensional array and two-dimensional array
Airserver automatically receives multi screen projection or cross device projection
HZOJ #236. 递归实现组合型枚举