visit数组存储 该数字是否有使用过
num数组 存储 将要匹配的数字
皆从下标1开始存储
static boolean[] visit = new boolean[14];
static int[] num = new int[13];
dfs 参数为填入的第几个数字 从上向下 从左往右
import java.util.*;import java.math.*;public class Main { static boolean[] visit = new boolean[14];static int[] num = new int[13];static int ans = 0;public static void main(String[]args) {Scanner in = new Scanner(System.in);dfs(0);System.out.print(ans);}public static void dfs(int step){if(step == 3) {if(num[1] + num[2] != num[3])return;}else if(step == 6) {if(num[4] - num[5] != num[6])return;}else if(step == 9) {if(num[7] * num[8] != num[9])return;}else if(step == 12) {if(num[10] / num[11] == num[12] && num[10] % num[11] == 0) {ans++;}return;}for(int i = 1 ; i < 14 ; ++ i) {if(!visit[i]) {num[step + 1] = i;visit[i] = true;dfs(step + 1);num[step + 1] = 0;visit[i] = false;}}}}