//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.4Eat the Trees",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=15,M=8192+3;",
            "int n,m,o,V,T,A[N][N];LL dp[2][M];",
            "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(T);",
            "\twhile(T--){",
            "\t\tin(n),in(m),V=(1<<m+1)-1;",
            "\t\tfor(Re i=1;i<=n;++i)",
            "\t\t\tfor(Re j=1;j<=m;++j)",
            "\t\t\t\tin(A[i][j]);",
            "\t\tfor(Re j=0;j<=V;++j)dp[0][j]=dp[1][j]=0;",
            "\t\tdp[o][0]=1;",
            "\t\tfor(Re i=1;i<=n;++i){",
            "\t\t\to^=1;",
            "\t\t\tfor(Re s=0;s<=V;++s)dp[o][s]=(s&1)?0:dp[o^1][s>>1];",
            "\t\t\tfor(Re j=1;j<=m;++j){",
            "\t\t\t\to^=1;",
            "\t\t\t\tfor(Re s=0;s<=V;++s)dp[o][s]=0;",
            "\t\t\t\tfor(Re s=0;s<=V;++s)if(dp[o^1][s]){",
            "\t\t\t\t\tRe L=(s>>j-1)&1,U=(s>>j+1-1)&1;",
            "\t\t\t\t\tif(A[i][j]){// 撤销操作",
            "\t\t\t\t\t\tdp[o][s^(1<<j-1)^(1<<j+1-1)]+=dp[o^1][s];",
            "\t\t\t\t\t\tif(L!=U)dp[o][s]+=dp[o^1][s];",
            "\t\t\t\t\t}",
            "\t\t\t\t\telse{",
            "\t\t\t\t\t\tif(!L&&!U)dp[o][s]+=dp[o^1][s];",
            "\t\t\t\t\t}",
            "\t\t\t\t}",
            "\t\t\t}",
            "\t\t}",
            "\t\tprintf(\"%lld\\n\",dp[o][0]);",
            "\t}",
            "}",
            ""
        ],
        "description": "插入 插头DP"
    }
}