Public classSolution {Private Boolean[] visited =New Boolean[3] [3]; Private intm; Private intN; Public intNumberofpatterns (intMintN) {if(n = = 0 | | m >N) {return0; } intresult = 0; This. m =m; This. N =N; for(inti = 0; I < 3; i++) { for(intj = 0; J < 3; J + +) {Visited[i][j]=true; Result+ = Getpattern (i, J, 1); VISITED[I][J]=false; } } returnresult; } Private intGetpattern (intXintYintLevel ) { if(Level >N) {return0; } intresult = Level >= m? 1:0; for(inti = 0; I < 3; i++) { for(intj = 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; } } returnresult; }}
1.3x3 Pattern board. Don't mess it up.
2. Pattern counting start from 1, not 0
Android Unlock Patterns