zoukankan      html  css  js  c++  java
  • 蓝桥杯寒假作业回溯法

    现在小学的数学题目也不是那么好玩的。
    看看这个寒假作业:

    □ + □ = □
    □ - □ = □
    □ × □ = □
    □ ÷ □ = □

    (如果显示不出来,可以参见【图1.jpg】)

    每个方块代表1~13中的某一个数字,但不能重复。
    比如:
    6 + 7 = 13
    9 - 8 = 1
    3 * 4 = 12
    10 / 2 = 5

    以及: 
    7 + 6 = 13
    9 - 8 = 1
    3 * 4 = 12
    10 / 2 = 5

    static int[] a=new  int[13];
        static boolean[] b=new boolean[13];
        static int count=0;
    
    System.out.println(f22(0)); 
    public static int f22(int t){
        	if (t==3) {
        		if (a[0]+a[1]!=a[2]) {
    				return 0;
    			}
    		}
        	if (t==6) {
        		if (a[3]-a[4]!=a[5]) {
    				return 0;
    			}
    		}
        	if (t==9) {
        		if (a[6]*a[7]!=a[8]) {
    				return 0;
    			}
    		}
        	if (t==13) {
        		if (a[9]*1.0/a[10]*1.0==a[11]) {
        			count++;
    			}
    		}
        	for (int i = 0; i < 13; i++) {
    			if (!b[i]) {
    				a[t]=i+1;
    				b[i]=true;
    				f22(t+1);
    				b[i]=false;
    			}
    		}
        	return count;
        }

    64

  • 相关阅读:
    2020/5/18
    2020/5/17
    2020/5/15
    2020/5/13
    2020/5/12
    服务器环境配置五大免费主机系统
    6:运算符
    5:练习题
    4:Python的while循环
    3:Python条件语句
  • 原文地址:https://www.cnblogs.com/chenxi001/p/11668233.html
Copyright © 2011-2022 走看看