关闭

FTPrep, 37 Sukodu Solver

136人阅读 评论(0) 收藏 举报
分类:

TODO: the explanation for the flow

1, recursive function: 3 key points

2, naming is important for logic and debugging, always having a good variable name

3, one-time bug free is left to do, first time is xxx minute and second

代码:

public class Solution {
    public void solveSudoku(char[][] board) {
        helper(board, 0, 0);    
    }
    
    private boolean helper(char[][] board, int row, int col){
        if(col==9) return helper(board, row+1, 0);
        if(row==9) return true;
        if(board[row][col]=='.'){
            for(int k=1; k<=9; k++){
                board[row][col] = (char)('0'+ k);
                if(isValid(board, row, col, board[row][col])){
                    if(helper(board, row, col+1)) return true;
                }
                board[row][col]='.';
            }
            return false;
        }
        else return helper(board, row, col+1);
    }
    
    private boolean isValid(char[][] board, int i, int j, char ch){
        for(int col=0; col<board[0].length; col++){
            if(col!=j&& ch==board[i][col]) return false;
        }
        for(int row=0; row<board.length; row++){
            if(row!=i&& ch==board[row][j]) return false;
        }
        for(int row=i/3*3; row<i/3*3 +3; row++){
            for(int col=j/3*3; col<j/3*3+3; col++){
                if((row!=i || col!=j) && ch==board[row][col]) return false;
            }
        }
        return true;
    }
}


0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

caffe solver参数意义与设置

batchsize:每迭代一次,网络训练图片的数量,例如:如果你的batchsize=256,则你的网络每迭代一次,训练256张图片;则,如果你的总图片张数为1280000张,则要想将你所有的图片通过...
  • qq_32206625
  • qq_32206625
  • 2016-09-22 11:27
  • 2178

关于solver设置的一些问题

转自:原文 solver算是caffe的核心的核心,它协调着整个模型的运作。caffe程序运行必带的一个参数就是solver配置文件。运行代码一般为 ./bulid/tools/caffe trai...
  • sinat_30071459
  • sinat_30071459
  • 2016-03-18 10:39
  • 3207

Caffe 初学拾遗(十二) Solver

{承接CNN学习入门,笔者在这里对Caffe官方网站上的相关介绍进行了翻译总结,欢迎大家交流指正} 本文基于此刻最新的release,Caffe-rc3: Solver: solver通过...
  • baidu_24281959
  • baidu_24281959
  • 2016-10-20 13:51
  • 1135

Sukodu Solver(深搜)

Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by t...
  • qq_33097439
  • qq_33097439
  • 2017-07-14 11:54
  • 61

DAY22:leetcode #37 Sudoku Solver

Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by t...
  • zcy19941015
  • zcy19941015
  • 2016-11-07 22:14
  • 124

37. Sudoku Solver

这样的题目一般通过回溯法求解,设置某个空格时,如果该空格无论设置什么数字都无法达到合法状态,那么回溯重新设置上一个空格,详见代码注释。注意,这样的题目一定要想明白每一处细节,才能够作对。代码如下: ...
  • wusecaiyun
  • wusecaiyun
  • 2015-07-21 17:41
  • 293

[LeetCode37]Soduko Solver

Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by t...
  • sbitswc
  • sbitswc
  • 2014-06-16 23:26
  • 550

[LeetCode 36&37] Valid Sudoku & Sudoku Solver (数独问题)

题目链接:valid-sudoku import java.util.Arrays; /** * Determine if a Sudoku is valid, according...
  • ever223
  • ever223
  • 2015-03-31 11:09
  • 545

LeetCode-37.Sudoku Solver

https://leetcode.com/problems/sudoku-solver/ Write a program to solve a Sudoku puzzle by fillin...
  • zmq570235977
  • zmq570235977
  • 2016-06-09 16:18
  • 326

Leetcode #37. Sudoku Solver 数独求解 结题报告

1 解题报告首先可以看下昨天的 Leetcode #36. Valid Sudoku 数独游戏验证 解题报告 数独的求解,这道题可以假设给定的这个是正确的做法就只能是暴力的回溯了。。 方法是回溯,用...
  • MebiuW
  • MebiuW
  • 2016-04-08 23:58
  • 885
    个人资料
    • 访问:21650次
    • 积分:2468
    • 等级:
    • 排名:第17224名
    • 原创:211篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条