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
Project: PatternLock
Path: src/pass_9.cpp
Views: 13#include <cstdio>1#include <cstring>2#define N 33#define DIGIT N*N4#define THRESHOLD 456using namespace std;78bool vis[DIGIT + 1];9int dp[DIGIT + 1][1<<(DIGIT + 1)][DIGIT + 1];10int ban[DIGIT + 1][DIGIT + 1] = {11{0,/*0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0},12// 0 1 2 3 4 5 6 7 8 913{0,/*1*/ 0, 0, 2, 0, 0, 0, 4, 0, 5},14{0,/*2*/ 0, 0, 0, 0, 0, 0, 0, 5, 0},15{0,/*3*/ 2, 0, 0, 0, 0, 0, 5, 0, 6},16{0,/*4*/ 0, 0, 0, 0, 0, 5, 0, 0, 0},17{0,/*5*/ 0, 0, 0, 0, 0, 0, 0, 0, 0},18{0,/*6*/ 0, 0, 0, 5, 0, 0, 0, 0, 0},19{0,/*7*/ 4, 0, 5, 0, 0, 0, 0, 0, 8},20{0,/*8*/ 0, 5, 0, 0, 0, 0, 0, 0, 0},21{0,/*9*/ 5, 0, 6, 0, 0, 0, 8, 0, 0}22};2324int dfs(int len, int pre, int status, bool is_zero) {25if(len <= 0) return 1;2627if(!is_zero && dp[len][status][pre] != -1)28return dp[len][status][pre];2930int sum = 0;31for(int i = 0; i <= DIGIT; i++) {32if(vis[i]) continue;3334if(is_zero) {35if(!i) {36if(len > THRESHOLD)37sum += dfs(len - 1, 0, 0, true);38}39else {40vis[i] = true;41sum += dfs(len - 1, i, 1<<i, false);42vis[i] = false;43}44}45else if(i) {46if(ban[pre][i] && vis[ban[pre][i]] == false) continue;47else {48vis[i] = true;49sum += dfs(len - 1, i, (1<<i) + status, false);50vis[i] = false;51}52}53}5455if(!is_zero)56dp[len][status][pre] = sum;5758return sum;59}6061int main() {62memset(vis, false, sizeof(vis));63memset(dp, -1, sizeof(dp));64printf("%d\n", dfs(DIGIT, 0, 0, true));6566return 0;67}6869