有1,2,2,3,4,5六个数,要求输出他们组合的全排列
来源:互联网 发布:网络主播招聘要求 编辑:程序博客网 时间:2024/04/29 16:27
import java.util.ArrayList;
import java.util.List;
public class Permutation {
public static List<String> permutation = new ArrayList<String>();
public static void main(String[] args) {
char[] numbers = new char[]{'1','2','2','3','4','5'};
permute(numbers, 0, numbers.length-1);
for(String str:permutation){
System.out.println(str);
}
}
private static void permute(char[] n, int cur, int end) {
if(cur == end){
String str = new String(n);
if(permutation.contains(str)||str.charAt(2)=='4'||str.contains("35")
||str.contains("53"))
return;
permutation.add(str);
return;
}
for(int i=cur; i<=end; i++){
swap(n, cur, i);
permute(n, cur+1, end);
swap(n, cur, i);
}
}
private static void swap(char[] n, int cur, int i) {
char temp = n[cur];
n[cur] = n[i];
n[i] = temp;
}
}
import java.util.List;
public class Permutation {
public static List<String> permutation = new ArrayList<String>();
public static void main(String[] args) {
char[] numbers = new char[]{'1','2','2','3','4','5'};
permute(numbers, 0, numbers.length-1);
for(String str:permutation){
System.out.println(str);
}
}
private static void permute(char[] n, int cur, int end) {
if(cur == end){
String str = new String(n);
if(permutation.contains(str)||str.charAt(2)=='4'||str.contains("35")
||str.contains("53"))
return;
permutation.add(str);
return;
}
for(int i=cur; i<=end; i++){
swap(n, cur, i);
permute(n, cur+1, end);
swap(n, cur, i);
}
}
private static void swap(char[] n, int cur, int i) {
char temp = n[cur];
n[cur] = n[i];
n[i] = temp;
}
}
0 0
- 有1,2,2,3,4,5六个数,要求输出他们组合的全排列
- 有1,2,2,3,4,5六个数,要求输出他们组合的全排列,4不能在第三位,5和3不能相邻
- 编程:用java 语言实现,输入一个数,就相应地输出的几维数组!||用1、2、2、3、4、5这六个数字,用java写一个函数,打印出所有不同的排列,要求:"4"不能在第三位,"3"与"5"不能相连
- 用 1,2,2,3,4,5 六个数字,打印出所有不同的排列,要求:"4"不能在第三位,"3"与"5"不能相连
- 用1、2、2、3、4、5这六个数字,打印出所有不同的排列
- 输出一个数全排列的组合【利用哈密尔顿图遍历算法实现】
- 【2015/10/13】打印1,2,2,3,4,5六个数的组合,4不在第三位,3和5不能相邻
- 用1、2、2、3、4、5这六个数字,用java写一个main函数,打印出所有不同的排列, 如:512234、412345等,要求:"4"不能在第三位,"3"与"5"不能相连.
- 用1、2、2、3、4、5这六个数字,写一个main函数,打印出所有不同的排列, 如:512234、412345等,要求:"4"不能在第三位,"3"与"5"不能相连.
- 1、2、2、3、4、5这六个数字,用java写一个main函数,打印出所有不同的排列, 如:512234、412345等.要求:"4"不能在第三位,"3"与"5"不能相连.
- 用1、2、2、3、4、5这六个数字,用java写一个程序,打印出所有不同的排列 如:512234、412345等,要求:"4"不能在第三位,"3"与"5"不能相连
- 用1、2、2、3、4、5这六个数字,用java写一个main函数,打印出所有不同的排列,如:512234、412345等,要求:"4"不能在第三位,"3"与"5"不能相连。
- 用1、2、2、3、4、5 这六个数字,用java 写一个main 函数,打印出所有不同的排列,要求:"4"不能在第三位,"3"与"5"不能相连。
- 用1、2、3、3、4、5这六个数字,用java写一个程序,打印出所有不同的排列 要求:"4"不能在第三位,"3"与"5"不能相连。
- 用1、2、3、3、4、5这六个数字,用java写一个程序,打印出所有不同的排列 要求:"4"不能在第三位,"3"与"5"不能相连。
- 用1、2、3、3、4、5这六个数字,用java写一个程序,打印出所有不同的排列 要求:"4"不能在第三位,"3"与"5"不能相连。
- 输入一个数n,输出1~n的全排列
- 输出一个数的全排列
- iOS HTTP访问网络受限
- Android中加载高清大图及图片压缩方式
- Android自定义View(一)---ListView 下拉刷新
- 微信公众平台小程序新增功能
- Android studio 用SVN Share 项目出现 Authentication required 的问题
- 有1,2,2,3,4,5六个数,要求输出他们组合的全排列
- EF更新数据库结构seed方法不执行
- MATLAB robotics tools工具箱下载安装
- Python知识点汇总
- 160. Intersection of Two Linked Lists leetcode (list)
- 数据结构经典面试题——练习4
- 关于Java EE的介绍
- SQL Server中,删除表,删除表中数据
- Python3 + django 支持 MySQL