Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
| Download
To calculate 3 order pattern lock
Project: PatternLock
Path: src/pass_16.cpp
Views: 28#include <cstdio>1#include <cstring>2#define N 43#define DIGIT N*N4#define THRESHOLD 456using namespace std;78bool vis[DIGIT + 1];9long long int dp[DIGIT + 1][1<<(DIGIT + 1)][DIGIT + 1];10int ban_1[DIGIT + 1][DIGIT + 1] = {11{0,/*0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},12// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1613{0,/*1*/ 0, 0, 2, 2, 0, 0, 0, 0, 5, 0, 6, 0, 5, 0, 0, 6},14{0,/*2*/ 0, 0, 0, 3, 0, 0, 0, 0, 0, 6, 0, 7, 0, 6, 0, 0},15{0,/*3*/ 2, 0, 0, 0, 0, 0, 0, 0, 6, 0, 7, 0, 0, 0, 7, 0},16{0,/*4*/ 2, 3, 0, 0, 0, 0, 0, 0, 0, 7, 0, 8, 7, 0, 0, 8},17{0,/*5*/ 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 9, 0,10, 0},18{0,/*6*/ 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0,10, 0,11},19{0,/*7*/ 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0,10, 0,11, 0},20{0,/*8*/ 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,11, 0,12},21{0,/*9*/ 5, 0, 6, 0, 0, 0, 0, 0, 0, 0,10,10, 0, 0, 0, 0},22{0,/*10*/0, 6, 0, 7, 0, 0, 0, 0, 0, 0, 0,11, 0, 0, 0, 0},23{0,/*11*/6, 0, 7, 0, 0, 0, 0, 0,10, 0, 0, 0, 0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/0, 7, 0, 8, 0, 0, 0, 0,11,11, 0, 0, 0, 0, 0, 0},45{0,/*13*/9, 0, 0,10, 9, 0,10, 0, 0, 0, 0, 0, 0, 0,14,15},46{0,/*14*/0,10, 0, 0, 0,10, 0,11, 0, 0, 0, 0, 0, 0, 0,15},47{0,/*15*/0, 0,11, 0,10, 0,11, 0, 0, 0, 0, 0,14, 0, 0, 0},48{0,/*16*/11,0, 0,12, 0,11, 0,12, 0, 0, 0, 0,15,15, 0, 0}49};5051long long int dfs(int len, int pre, int status, bool is_zero) {52if(len <= 0) return 1;5354if(!is_zero && dp[len][status][pre] != -1)55return dp[len][status][pre];5657long long int sum = 0;58for(int i = 0; i <= DIGIT; i++) {59if(vis[i]) continue;6061if(is_zero) {62if(!i) {63if(len > THRESHOLD)64sum += dfs(len - 1, 0, 0, true);65}66else {67vis[i] = true;68sum += dfs(len - 1, i, 1<<i, false);69vis[i] = false;70}71}72else if(i) {73if(!ban_1[pre][i] || (vis[ban_1[pre][i]] && vis[ban_2[pre][i]])) {74vis[i] = true;75sum += dfs(len - 1, i, (1<<i) + status, false);76vis[i] = false;77}78}79}8081if(!is_zero)82dp[len][status][pre] = sum;8384return sum;85}8687int main() {88memset(vis, false, sizeof(vis));89memset(dp, -1, sizeof(dp));90printf("%lld\n", dfs(DIGIT, 0, 0, true));9192return 0;93}949596