博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android Unlock Patterns
阅读量:7045 次
发布时间:2019-06-28

本文共 1381 字,大约阅读时间需要 4 分钟。

public class Solution {    private boolean[][] visited = new boolean[3][3];    private int m;    private int n;    public int numberOfPatterns(int m, int n) {        if (n == 0 || m > n) {            return 0;        }        int result = 0;        this.m = m;        this.n = n;        for (int i = 0; i < 3; i++) {            for (int j = 0; j < 3; j++) {                visited[i][j] = true;                result += getPattern(i, j, 1);                visited[i][j] = false;            }        }        return result;    }            private int getPattern(int x, int y, int level) {        if (level > n) {            return 0;        }                int result = level >= m ? 1 : 0;        for (int i = 0; i < 3; i++) {            for (int j = 0; j < 3; j++) {                if (visited[i][j] ||                x == i && Math.abs(y - j) == 2 && !visited[i][1] ||                y == j && Math.abs(x - i) == 2 && !visited[1][j] ||                Math.abs(x - i) == 2 && Math.abs(y - j) == 2 && !visited[1][1]) {                    continue;                }                visited[i][j] = true;                result += getPattern(i, j, level + 1);                visited[i][j] = false;            }        }        return result;    }}

 

 

1. 3x3 pattern board. Do not mess it up.

2. pattern counting start from 1, not 0

转载于:https://www.cnblogs.com/shuashuashua/p/5619059.html

你可能感兴趣的文章
2013年4月IT技术行业网站综合影响力排名
查看>>
Magento session机制的分析与应用
查看>>
linux 服务器长ping 加时间戳;转
查看>>
http与https的区别
查看>>
一些可以查询IP地理位置、身份证所在地、手机归属地的接口
查看>>
鼠标滚动插件smoovejs和wowjs
查看>>
我的友情链接
查看>>
javascript学习记录-数组(8)-完结 2014/02/26
查看>>
读取通讯录联系人
查看>>
ssh三大框架简单整合,struts2整合JasperReport报表、图表,解决HTML显示图片不出来,PDF中文不显示的问题...
查看>>
XML基础知识
查看>>
telnet: Unable to connect to remote host: No route to host处理过程
查看>>
我的友情链接
查看>>
单元测试Struts2的Action(包含源码)
查看>>
简要总结最近遇到的5个问题
查看>>
我的友情链接
查看>>
高校专业机房使用VMware Player解决方案
查看>>
我的友情链接
查看>>
Centos Development Tools 安装
查看>>
1.1.2 C++发展历程
查看>>