当前位置:网站首页>【全排列】
【全排列】
2022-08-09 00:03:00 【咕噜鸭】
理解
在数组下标p到q范围里的所有元素,逐一与数组第一个元素交换位置,然后下标p+1到q里的元素继续全排列,直到下标p=q时停止全排列,最后把刚才交换的两个元素再换回来,以便下一个元素与首元素交换位置,避免重复出现的情况。
代码
public static void dfs(int a[],int p,int q) {
if(p == q) {
for(int i=0;i<a.length();i++){
System.out.print(a[i]);
}
return ;
}
for(int i=p;i<=q;i++) {
swap(p,i);
dfs(a,p+1,q);
swap(p,i);
}
}
边栏推荐
猜你喜欢
随机推荐
RIP 实验
Idea碰到的问题总结
重发布实验
Get the start time and end time of the current month half a year ago
MySql 删除数据表
并发专题第一篇,多线程快速入门和简单介绍
穿越派·派盘+KeePass = 最安全的私人密码管理方案
Intelligent search baidu map and drag the picture circle
ES6入门基础知识
穿越派·派盘 + 静读天下 = 顶级电子书阅读器
我们的爱恨情仇:人性-关系-危机-和谐的科学研究
BGP第二天总结作业
关于字符串根据字典序排序的方法
将板子芯片从ST32F101改为STM32F103要改的地方
vspm虚拟串口调试
snmp获取agent OID,及MibBrowser使用
Ubuntu下Docker安装Redis (快速简便)
Get the current week time excluding the current day
reits基金是什么意思?安全吗?
随笔-2018.4.3