当前位置:网站首页>7-3 组合问题(*)
7-3 组合问题(*)
2022-06-11 18:34:00 【见闻色霸气~】
题目信息
从 m (0<m≤26) 个大写字母中任意选出 n (0<n≤m) 个字母组合到一起,一共有多少种组合?
请编写程序,输入 m 和 n,输出从 A 开始的连续 m 个字母中任取 n 个字母的所有组合。
要求:每行输出一个组合(组合内的字母按升序排序),按字典序输出。
输入样例
4 3
输出样例
ABC
ABD
ACD
BCD
代码:
dfs直接写就行,题目要求是要升序。那就用两个参数。
#include<bits/stdc++.h>
using namespace std;
int m, n;
char q[30] = {
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
char p[50];
void dfs(int u,int s)
{
if (u == n) {
for (int i = 0; i < n; i++) {
printf("%c", p[i]);
}
puts("");
return;
}
for (int i = s; i < m; i++) {
p[u] = q[i];
dfs(u + 1, i + 1);
}
}
int main()
{
cin >> m >> n;
dfs(0,0);
}
边栏推荐
- 【题解】Codeforces Round #798 (Div. 2)
- Realize that you can continue to play
- Two methods for matlab to save imshow drawing pictures to a specified folder
- Cool visualization tool: first introduction to processing
- 开发中必备的文件的上传与下载
- Uploading and downloading of necessary files in development
- 动态爆炸效果
- SQL注入漏洞学习之一:phpstudy集成环境搭建DVWA靶场
- 力扣32题最长有效括号
- Ti am64x - the latest 16nm processing platform, designed for industrial gateways and industrial robots
猜你喜欢

力扣23题,合并K个升序链表

v-for循环遍历

map和set

Force deduction questions -- create a string based on a binary tree

Non recursive traversal of binary tree

* Jetpack 笔记 Room 的使用

牛客刷题——求最小公倍数

Async leads to unexpected function results and changes the intention of the original code; await is only valid in async functions and the top level bodies of modules
Complete in-depth learning of MySQL from 0 to 1 -- phase 2 -- basics
MySQL in-depth and complete learning - stage 1 - overview of learning
随机推荐
Let our tanks move happily
Force deduction 33 questions, search rotation sorting array
DataNode的启动流程
北京邮电大学2023级工商管理硕士MBA(非全日制)已开启
Analysis of runtime instantiation of XML view root node in SAP ui5
基于TI AM5728 + Artix-7 FPGA开发板(DSP+ARM) 5G通信测试手册
Do you know that public fields are automatically filled in
牛客刷题——两种排序方法
全志科技T3開發板(4核ARM Cortex-A7)——MQTT通信協議案例
Feign shares login information for request
New project construction environment method
2022-2023 MEM pre approval interview notice of School of management, Xi'an Jiaotong University
构造敌方坦克
对‘g2o::VertexSE3::VertexSE3()’未定义的引用
2023年西安交通大学管理学院MPAcc提前批面试网报通知
牛客刷题——求最小公倍数
Niuke brush questions part6
Overall process of software development
使用Transformers将TF模型转化成PyTorch模型
Niu Ke's questions -- two sorting methods