zoukankan      html  css  js  c++  java
  • 凑算式 蓝桥杯

    凑算式
    
         B      DEF
    A + --- + ------- = 10
         C      GHI
         
    (如果显示有问题,可以参见【图1.jpg】)
         
         
    这个算式中A~I代表1~9的数字,不同的字母代表不同的数字。
    
    比如:
    6+8/3+952/714 就是一种解法,
    5+3/1+972/486 是另一种解法。
    
    这个算式一共有多少种解法?
    
    注意:你提交应该是个整数,不要填写任何多余的内容或说明性文字。

    全排列思想:https://www.cnblogs.com/chiweiming/p/9279858.html

    import java.util.Scanner;
    
    public class Main {
        
        static long res=0;
        static int book[]=new int[10];    //标记第i个数是否已经使用
        static double arr[]=new double[10];    //存放全排列
        
        static void solve(int first,int last,int count){
            if(count==10){
                if((arr[1]+arr[2]/arr[3]+(arr[4]*100+arr[5]*10+arr[6])/(arr[7]*100+arr[8]*10+arr[9]))==10){
                    res++;
                }
                return;
            }
            for(int i=first;i<=last;i++){
                if(book[i]==0){
                    book[i]=1;
                    arr[count]=i;
                    solve(first,last,count+1);
                    book[i]=0;    //回溯
                }
            }
        }
        
        public static void main(String[] args){
            solve(1,9,1);
            System.out.print(res);
        }
    }

    答案:29

  • 相关阅读:
    2019.1.10英语笔记
    2019.1.9专业课笔记
    团队触发器
    团队脚本备份
    导表
    oslo.config
    nginx启动、重启、关闭
    常见的awk内建变量
    LVM
    Django, one-to-many, many-to-many
  • 原文地址:https://www.cnblogs.com/chiweiming/p/10515999.html
Copyright © 2011-2022 走看看