//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 的格式要求是 "插入 [该代码片段的中文名]"

{
    "地板": {
        "prefix": "acm-5.4三进制插头dp",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=103,M=177147+3,P=20110520;",
            "int n,m,o,V,Mi[N],A[N][N],A_[N][N],dp[2][M];char s[N];//0:没有插头 1:还没完成的插头 2:已经完成的插头",
            "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;",
            "}",
            "inline void mo(Re &x){if(x>P)x-=P;}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(m);",
            "\tfor(Re i=1;i<=n;++i){",
            "\t\tscanf(\"%s\",s+1);",
            "\t\tfor(Re j=1;j<=m;++j)A[i][j]=(s[j]=='*');",
            "\t}",
            "\tif(n<m){",
            "\t\tfor(Re i=1;i<=n;++i)",
            "\t\t\tfor(Re j=1;j<=m;++j)",
            "\t\t\t\tA_[j][i]=A[i][j];",
            "\t\tswap(n,m);",
            "\t\tfor(Re i=1;i<=n;++i)",
            "\t\t\tfor(Re j=1;j<=m;++j)",
            "\t\t\t\tA[i][j]=A_[i][j];",
            "\t}",
            "\tMi[0]=1;for(Re i=1;i<=m+1;++i)Mi[i]=Mi[i-1]*3;",
            "\tV=Mi[m+1]-1,dp[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,ML=Mi[j-1],MU=Mi[j+1-1];",
            "\t\t\t\tif(A[i][j]){",
            "\t\t\t\t\tif(!L&&!U)mo(dp[o][s]+=dp[o^1][s]);",
            "\t\t\t\t}",
            "\t\t\t\telse{",
            "\t\t\t\t\tif(L==0&&U==0){",
            "\t\t\t\t\t\tmo(dp[o][s+ML]+=dp[o^1][s]);",
            "\t\t\t\t\t\tmo(dp[o][s+MU]+=dp[o^1][s]);",
            "\t\t\t\t\t\tmo(dp[o][s+2*ML+2*MU]+=dp[o^1][s]);",
            "\t\t\t\t\t}",
            "\t\t\t\t\tif(L==0&&U==1){",
            "\t\t\t\t\t\tmo(dp[o][s+MU]+=dp[o^1][s]);",
            "\t\t\t\t\t\tmo(dp[o][s+ML-MU]+=dp[o^1][s]);",
            "\t\t\t\t\t}",
            "\t\t\t\t\tif(L==0&&U==2){",
            "\t\t\t\t\t\tmo(dp[o][s+2*ML-2*MU]+=dp[o^1][s]);",
            "\t\t\t\t\t\tmo(dp[o][s-2*MU]+=dp[o^1][s]);",
            "\t\t\t\t\t}",
            "\t\t\t\t\tif(L==1&&U==0){",
            "\t\t\t\t\t\tmo(dp[o][s+ML]+=dp[o^1][s]);",
            "\t\t\t\t\t\tmo(dp[o][s-ML+MU]+=dp[o^1][s]);",
            "\t\t\t\t\t}",
            "\t\t\t\t\tif(L==1&&U==1)mo(dp[o][s-ML-MU]+=dp[o^1][s]);",
            "\t\t\t\t\tif(L==1&&U==2);",
            "\t\t\t\t\tif(L==2&&U==0){",
            "\t\t\t\t\t\tmo(dp[o][s-2*ML+2*MU]+=dp[o^1][s]);",
            "\t\t\t\t\t\tmo(dp[o][s-2*ML]+=dp[o^1][s]);",
            "\t\t\t\t\t}",
            "\t\t\t\t\tif(L==2&&U==1);",
            "\t\t\t\t\tif(L==2&&U==2);",
            "\t\t\t\t}",
            "\t\t\t}",
            "\t\t}",
            "\t}",
            "\tprintf(\"%d\\n\",dp[o][0]);",
            "}",
            ""
        ],
        "description": "插入 地板"
    }
}