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

{
    "对抗搜索+记忆化  (一双木棋chess)": {
        "prefix": "acm-7.3最大分数",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<map>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=13,inf=2e9;",
            "int n,m,cnt,h[N],can[N],vis[N][N],A[2][N][N];",
            "map<LL,int>pan;",
            "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 LL Hash(Re op){LL ans=op+1;for(Re i=1;i<=n;++i)ans=ans*11ll+h[i];return ans;}",
            "inline int dfs(Re op){",
            "\tif(cnt==n*m)return 0;",
            "\tLL H=Hash(op);",
            "\tif(pan.find(H)!=pan.end())return pan[H];",
            "\tRe ans=op?-inf:inf;",
            "\tfor(Re i=1,j;i<=n;++i)",
            "\t\tif(h[i]<m&&vis[i][j=h[i]+1]==-1&&h[i-1]>=j){",
            "\t\t\tvis[i][j]=op,++cnt,++h[i];",
            "\t\t\tif(op)ans=max(ans,dfs(op^1)+A[op][i][j]);",
            "\t\t\telse ans=min(ans,dfs(op^1)-A[op][i][j]);",
            "\t\t\tvis[i][j]=-1,--cnt,--h[i];",
            "\t\t}",
            "\treturn pan[H]=ans;",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(m);",
            "\tfor(Re i=1;i<=n;++i)",
            "\t\tfor(Re j=1;j<=m;++j)",
            "\t\t\tin(A[1][i][j]);",
            "\tfor(Re i=1;i<=n;++i)",
            "\t\tfor(Re j=1;j<=m;++j)",
            "\t\t\tin(A[0][i][j]);",
            "\tmemset(vis,-1,sizeof(vis));",
            "\th[0]=inf;",
            "\tprintf(\"%d\\n\",dfs(1));",
            "}",
            ""
        ],
        "description": "插入 对抗搜索+记忆化  (一双木棋chess)"
    }
}