//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.2金明的预算方案",
        "body": [
            "#include<algorithm>",
            "#include<cstdio>",
            "using namespace std;",
            "int T,n,i,j,a[65],s,t,r1,r2,r[65][3],v[65],w[65],f[32010];",
            "int main(){",
            "    scanf(\"%d%d\",&T,&n);",
            "    v[0]=0xfffffff;",
            "    for(i=1;i<=n;i++){",
            "        scanf(\"%d%d%d\",&v[i],&s,&a[i]);",
            "        if(a[i])r[a[i]][++r[a[i]][0]]=i;w[i]=v[i]*s;",
            "    }",
            "    for(i=1;i<=n;i++)",
            "        for(j=T;j>=v[i]&&(!a[i]);j--){",
            "            t=j-v[i],r1=r[i][1],r2=r[i][2];",
            "            f[j]=max(f[j],f[t]+w[i]);",
            "            if(v[r1]<=t)f[j]=max(f[j],f[t-v[r1]]+w[i]+w[r1]);",
            "            if(v[r2]<=t)f[j]=max(f[j],f[t-v[r2]]+w[i]+w[r2]);",
            "            if(v[r1]+v[r2]<=t)f[j]=max(f[j],f[t-v[r1]-v[r2]]+w[i]+w[r1]+w[r2]);",
            "        }",
            "    printf(\"%d\",f[T]);",
            "}",
            ""
        ],
        "description": "插入 分组背包"
    }
}