美文网首页
351. Android Unlock Patterns

351. Android Unlock Patterns

作者: 我是你的果果呀 | 来源:发表于2016-12-10 07:28 被阅读0次

    Given an Android3x3key lock screen and two integersmandn, where 1 ≤ m ≤ n ≤ 9, count the total number of unlock patterns of the Android lock screen, which consist of minimum ofmkeys and maximumnkeys.
    Rules for a valid pattern:
    Each pattern must connect at leastmkeys and at mostnkeys.
    All the keys must be distinct.
    If the line connecting two consecutive keys in the pattern passes through any other keys, the other keys must have previously selected in the pattern. No jumps through non selected key is allowed.
    The order of keys used matters.

    这个题真的有点复杂, 觉得应该hard level 的 =.=!!! , backtracking , recursion ,还有思维巧妙。

    1: 1379 这四个数是对称的, 1有多少种可能, 其他三个数也有多少种可能, 所以算的时候 只算一个再乘以4得到他们总和。  2468 同理。
    2: 数字不能跳着选, 所以如果是跳着的, 中间间隔的那个数字必须是已经选中过了, 这样引申出来两个数组, boolean[] visited,  int[][] skips; 
    3:  递归回溯每个数字的可能性。

    还得再看一遍。不容易想

    相关文章

      网友评论

          本文标题:351. Android Unlock Patterns

          本文链接:https://www.haomeiwen.com/subject/lgbymttx.html