当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Multi row and multi column flex layout
[statistical learning method] learning notes - support vector machine (I)
Dialogue with Wang Wenyu, co-founder of ppio: integrate edge computing resources and explore more audio and video service scenarios
【统计学习方法】学习笔记——第五章:决策树
浅谈估值模型 (二): PE指标II——PE Band
Financial data acquisition (III) when a crawler encounters a web page that needs to scroll with the mouse wheel to refresh the data (nanny level tutorial)
【统计学习方法】学习笔记——逻辑斯谛回归和最大熵模型
SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
Routing strategy of multi-point republication [Huawei]
随机推荐
2022聚合工艺考试题模拟考试题库及在线模拟考试
[play RT thread] RT thread Studio - key control motor forward and reverse rotation, buzzer
leetcode刷题:二叉树19(合并二叉树)
Airserver automatically receives multi screen projection or cross device projection
Day-15 common APIs and exception mechanisms
SQL Lab (36~40) includes stack injection, MySQL_ real_ escape_ The difference between string and addslashes (continuous update after)
【统计学习方法】学习笔记——支持向量机(下)
HZOJ #235. 递归实现指数型枚举
Day-14 common APIs
【从 0 开始学微服务】【00】课程概述
[deep learning] image multi label classification task, Baidu paddleclas
Niuke website
基于NeRF的三维内容生成
Tutorial on principles and applications of database system (009) -- conceptual model and data model
BGP actual network configuration
RHSA first day operation
About IPSec
Day-18 hash table, generic
Routing strategy of multi-point republication [Huawei]
[statistical learning methods] learning notes - Chapter 5: Decision Tree