标签:
不理解或者需要交流的同学可以粉我新浪微博@雷锹,私信哟!!!
每题都写思路效率太低了,有需要或者是实在不明白去我微博私信一下我更新博客
package com.jueshai2014; import java.util.Arrays; import java.util.Scanner; public class _4 { public static char [] array; public static boolean flag []; public static char[] all_P ; public static int count = 0; public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); String string = scan.next(); array = string.toCharArray(); Arrays.sort(array); flag= new boolean[array.length]; all_P = new char[array.length]; dfs(0,string); } private static void dfs(int n,String string) { // TODO Auto-generated method stub if(n == array.length){ if(string.equals(String.valueOf(all_P))){ System.out.println(count); } // System.out.println(String.valueOf(all_P)+ " " + count); count++; return; } for(int i = 0; i < array.length; i++){ if(!flag[i]){ flag[i] = true; all_P[n] = array[i]; dfs(n+1, string); flag[i] = false; } } } }
标签:
原文地址:http://blog.csdn.net/u013993712/article/details/51364545