题目描述
解题思路
全排列回溯
代码如下
import java.util.Scanner;public class Main {static int []arr{1,2,3,4,5,6,7,8,9};static int n;static int count0;public static void main(String[] args) {// TODO Auto-generated method stubScanner scannernew Scanner(System.in);nscanner.nextInt();qpl(0);System.out.println(count);}//全排列public static void qpl(int n) {if (n9) {scc(arr);}for (int i n; i < 9; i) {int zjsarr[i];arr[i]arr[n];arr[n]zjs;qpl(n1);//回溯zjsarr[i];arr[i]arr[n];arr[n]zjs;}}public static void scc(int []arr) {for (int i 1; i n) {continue;}for (int j 1; j qd; i--) {numarr[i]*nn;nn*10;}return num;}} 李白打酒
题目描述
解题思路
递归模拟
代码如下
class Main{static int count 0;public static void main(String[] args) {int n 2;dfs(2,0,0);System.out.println(count);}public static void dfs(int n,int d,int h){if(n1 5 9){count;return;}if(n5 || h>9){return;}dfs(n-1,d,h1);dfs(n*2,d1,h);}}