小编Sha*_*awn的帖子

如何找到公式的所有可能解决方案,如100*7-8*3 + 7?(10个猫中有8个是倒数解算器)

为了好玩我决定写一个简单的程序,可以解决8个十分之一的猫倒数数字拼图,链接是形式倒计时,但相同的规则.所以我的程序只是通过AxBxCxDxExF的所有可能组合,其中字母是数字,"x"是+, - ,/和*.这是它的代码:

private void combineRecursive( int step, int[] numbers, int[] operations, int combination[]){
    if( step%2==0){//even steps are numbers
        for( int i=0; i<numbers.length; i++){
            combination[ step] = numbers[ i];
            if(step==10){//last step, all 6 numbers and 5 operations are placed
                int index = Solution.isSolutionCorrect( combination, targetSolution);
                if( index>=0){
                    solutionQueue.addLast( new Solution( combination, index));
                }
                return;
            }
            combineRecursive( step+1, removeIndex( i, numbers), operations, combination);
        }
    }else{//odd steps are operations
        for( int i=0; i<operations.length; i++){
            combination[ step] = operations[ i];
            combineRecursive( …
Run Code Online (Sandbox Code Playgroud)

java tree recursion tree-balancing

10
推荐指数
1
解决办法
912
查看次数

标签 统计

java ×1

recursion ×1

tree ×1

tree-balancing ×1