package basic; import java.util.Scanner; public class kunnandechuan { static int count; public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int L = sc.nextInt(); String s = ""; dfs(n,L,s); } public static void dfs(int n,int L,String s){ for(char i = 'A';i < 'A' + L;i++){ if (isHard(s,i)){ String ss = s + i; count++;//计数,字典序第n小时打印 if(count == n){ System.out.println(ss); System.exit(0); } dfs(n,L,ss); } } } public static boolean isHard(String s,char i){ int len = 0; for(int j = s.length()-1;j>=0;j-=2) { String s1 = s.substring(j,j+len+1); String s2 = s.substring(j+len+1)+i; len++; if(s1.equals(s2)) { return false; } } return true; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)