//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "插头DP  (括号表示法)": {
        "prefix": "acm-5.4单回路",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=14,M=1594323+3;",
            "int n,m,o,V,edx,edy,Mi[N],A[N][N];LL ans,dp[2][M];char s[N];",
            "inline void in(Re &x){",
            "    int f=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')f|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=f?-x:x;",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(m),Mi[0]=1;",
            "\tfor(Re i=1;i<=m+1;++i)Mi[i]=Mi[i-1]*3;V=Mi[m+1]-1;",
            "\tfor(Re i=1;i<=n;++i){",
            "\t\tscanf(\"%s\",s+1);",
            "\t\tfor(Re j=1;j<=m;++j)if(!(A[i][j]=(s[j]=='*')))edx=i,edy=j;",
            "\t}",
            "//\tprintf(\"edx=%d, edy=%d\\n\",edx,edy);",
            "\tdp[o][0]=1;",
            "\tfor(Re i=1;i<=n;++i){",
            "\t\to^=1;",
            "\t\tfor(Re s=0;s<=V;++s)dp[o][s]=s%3?0:dp[o^1][s/3];",
            "\t\tfor(Re j=1;j<=m;++j){",
            "\t\t\to^=1;",
            "\t\t\tfor(Re s=0;s<=V;++s)dp[o][s]=0;",
            "\t\t\tfor(Re s=0;s<=V;++s)if(dp[o^1][s]){",
            "\t\t\t\tRe L=s/Mi[j-1]%3,U=s/Mi[j+1-1]%3;",
            "\t\t\t\tif(A[i][j]){if(!L&&!U)dp[o][s]+=dp[o^1][s];}",
            "\t\t\t\telse if(!L&&!U)dp[o][s+Mi[j-1]+2*Mi[j+1-1]]+=dp[o^1][s];",
            "\t\t\t\telse if(!L&&U)dp[o][s]+=dp[o^1][s],dp[o][s+U*Mi[j-1]-U*Mi[j+1-1]]+=dp[o^1][s];",
            "\t\t\t\telse if(L&&!U)dp[o][s]+=dp[o^1][s],dp[o][s-L*Mi[j-1]+L*Mi[j+1-1]]+=dp[o^1][s];",
            "\t\t\t\telse if(L==1&&U==1){",
            "\t\t\t\t\tRe cnt=1;",
            "\t\t\t\t\tfor(Re k=j+2;k<=m;++k){",
            "\t\t\t\t\t\tif(s/Mi[k-1]%3==1)++cnt;",
            "\t\t\t\t\t\telse if(s/Mi[k-1]%3==2)--cnt;",
            "\t\t\t\t\t\tif(!cnt){dp[o][s-Mi[j-1]-Mi[j+1-1]-Mi[k-1]]+=dp[o^1][s];break;}",
            "\t\t\t\t\t}",
            "\t\t\t\t}",
            "\t\t\t\telse if(L==2&&U==2){",
            "\t\t\t\t\tRe cnt=1;",
            "\t\t\t\t\tfor(Re k=j-1;k>=1;--k){",
            "\t\t\t\t\t\tif(s/Mi[k-1]%3==1)--cnt;",
            "\t\t\t\t\t\telse if(s/Mi[k-1]%3==2)++cnt;",
            "\t\t\t\t\t\tif(!cnt){dp[o][s-2*Mi[j-1]-2*Mi[j+1-1]+Mi[k-1]]+=dp[o^1][s];break;}",
            "\t\t\t\t\t}",
            "\t\t\t\t}",
            "\t\t\t\telse if(L==2&&U==1)dp[o][s-2*Mi[j-1]-Mi[j+1-1]]+=dp[o^1][s];",
            "\t\t\t\telse if(L==1&&U==2)if(i==edx&&j==edy&&!(s-Mi[j-1]-2*Mi[j+1-1]))ans+=dp[o^1][s];",
            "\t\t\t}",
            "\t\t}",
            "\t}",
            "\tprintf(\"%lld\\n\",ans);",
            "}",
            ""
        ],
        "description": "插入 插头DP  (括号表示法)"
    }
}