当前位置:网站首页>全排列问题2
全排列问题2
2022-08-06 15:13:00 【-JMY-】
题目描述
输入n输出1..n个数的全部排列。全部排列中,数字可以重复 。
例如输入3,输出全部排列的结果如下111、112、113、121、122、123、131、132、133、211、212、213、221、222、223、231、232、233、311、312、313、321、322、323、331、332、333。
输入
输出
样例输入
2
样例输出
11
12
21
22
参考代码:
#include<bits/stdc++.h>
using namespace std;
int n,a[10];
void dfs(int k){
if(k==n+1){
for(int i=1;i<=n;i++)
printf("%d",a[i]);
printf("\n");
return;
}
for(int i=1;i<=n;i++){
a[k]=i;
dfs(k+1);
}
}
int main(){
scanf("%d",&n);
dfs(1);
return 0;
}
边栏推荐
猜你喜欢

The real question of the ladder game - 7-6 boss's schedule (25 points)

Samsung's Vietnam factory is operating at less than half, regretting closing production lines in China

如何从一个空有上进心的人,变成行动上的巨人?

中国制造实力强横的又一证明,500强的中国企业数量最多

国内智能音箱半年销量爆降

Intel转型未成功而陷入亏损,AMD再次增长并获得可观的利润

HJLL-99/A数字零序电流继电器

Field userService in com.zher.reggie_task_out.controller.UserController required a bean of type ‘com

终于有人把IaaS、PaaS、SaaS讲明白了

交换排序—冒泡排序和快速排序
随机推荐
DL-24C/2A电流继电器
1322_FreeRTOS中的队列使用的信息梳理以及初步队列的使用
LeetCode Brushing Diary: 1545. Find the Kth bit in the Nth binary string
【C补充】二维数组作为形式参数的注意事项
From technical panorama to scene combat, analyze the evolutionary breakthrough of "narrowband HD"
stc8a--al422B————01,硬件上RE已经接地了。
启牛帮开通的中信证券VIP账户是安全的吗?怎么开
7 public accounts with excellent reputation!
LeetCode_递归_中等_397.整数替换
博云入选 Gartner 中国云原生领域代表性厂商
程序员最想干的三件事!
LeetCode:206. 反转链表————简单
Unstoppable, a major breakthrough in China's chip manufacturing industry chain, 5nm equipment will soon be sent to TSMC
LeetCode 1408. 数组中的字符串匹配
Practical+Reverse+Engineering Chapter 3 List Exercises
js array to remove the specified element [function encapsulation] (including object array to remove the specified element)
ES core concepts
Kotlin 协程之取消与异常处理探索之旅(下)
小程序跳转方式
odoo 网站教程-主题