{"id":462,"date":"2018-12-08T11:49:50","date_gmt":"2018-12-08T03:49:50","guid":{"rendered":"http:\/\/SmokeyDays.top\/wordpress\/?p=462"},"modified":"2018-12-08T11:50:21","modified_gmt":"2018-12-08T03:50:21","slug":"lp2540-noip2015-%e6%96%97%e5%9c%b0%e4%b8%bb%e5%a2%9e%e5%bc%ba%e7%89%88","status":"publish","type":"post","link":"http:\/\/SmokeyDays.top\/wordpress\/2018\/12\/08\/lp2540-noip2015-%e6%96%97%e5%9c%b0%e4%b8%bb%e5%a2%9e%e5%bc%ba%e7%89%88\/","title":{"rendered":"lp2540 NOIP2015 \u6597\u5730\u4e3b\u589e\u5f3a\u7248"},"content":{"rendered":"<p>\u9996\u5148\uff0c\u6211\u4eec\u6ce8\u610f\u5230\u82b1\u8272\u5bf9\u4e8e\u6597\u5730\u4e3b\u4e0d\u4f1a\u9020\u6210\u4efb\u4f55\u5f71\u54cd\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5ffd\u89c6\u6389\u82b1\u8272\u8fd9\u4e2a\u4fe1\u606f\u3002<br \/>\n\u7136\u540e\uff0c\u6211\u4eec\u5c06\u5269\u4f59\u7684\u4fe1\u606f\uff0c\u4f9d\u636e\u6570\u7801\u7684\u4ece\u5c0f\u5230\u5927\u50a8\u5b58\u3002<br \/>\n\u7136\u540e\u6211\u4eec\u53ef\u4ee5\u6ce8\u610f\u5230\uff0c\u5bf9\u4e8e\u4e00\u79cd\u51fa\u724c\u65b9\u5f0f\uff0c\u8c03\u6574\u4e00\u4e9b\u724c\u7ec4\u7684\u51fa\u724c\u987a\u5e8f\u5bf9\u7b54\u6848\u5e76\u4e0d\u4f1a\u9020\u6210\u5f71\u54cd\u3002<br \/>\n\u5e76\u4e14\uff0c\u6563\u724c\u4f3c\u4e4e\u5177\u6709\u8d2a\u5fc3\u7684\u6027\u8d28\u3002\u770b\u8d77\u6765\u5982\u679c\u80fd\u51fa\u4e09\u5e26\u4e8c\u90a3\u4e48\u51fa\u4e09\u5e26\u4e00\u5c31\u4e0d\u4f1a\u66f4\u4f18\uff0c\u5982\u679c\u80fd\u51fa\u56db\u5e26\u4e8c\u90a3\u51fa\u4e09\u5e26\u4e8c\u5c31\u4e0d\u4f1a\u66f4\u4f18\u3002<br \/>\n\u5bf9\u4e8e\u987a\u5b50\u7684\u60c5\u51b5\u662f\u4e00\u4e2a\u4f8b\u5916\uff0c\u56e0\u4e3a\u5982\u679c\u80fd\u51fa\u987a\u5b50\u7684\u8bdd\uff0c\u53ef\u80fd\u5b58\u5728\u4e00\u79cd\u60c5\u51b5\uff0c\u4f7f\u5f97\u4e0d\u51fa\u987a\u5b50\u6bd4\u51fa\u987a\u5b50\u66f4\u4f18\uff1b\u4ea6\u6709\u53ef\u80fd\u5c06\u4e00\u4e2a\u987a\u5b50\u51fa\u4e00\u90e8\u5206\u4f1a\u66f4\u4f18\u3002\u6545\u800c\u5bf9\u4e8e\u987a\u5b50\u5e94\u8be5\u7206\u641c\u5224\u5b9a\u3002<br \/>\n\u603b\u7ed3\u8d77\u6765\u5c31\u662f\uff1a\u7206\u641c\u51fa\u987a\u5b50\uff0c\u8d2a\u5fc3\u51fa\u6563\u724c\u3002<br \/>\n\u4f46\u662f\u4ed4\u7ec6\u8003\u8651\uff0c\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u8fd9\u79cd\u8d2a\u5fc3\u662f\u4e00\u79cd\u60f3\u5f53\u7136\u7684\u5bf9\u6b63\u786e\u7b54\u6848\u7684\u8fd1\u4f3c\u3002\u8fd9\u4e8b\u5b9e\u4e0a\u4ec5\u56e0\u4e3a\u56db\u4e0d\u53ef\u5e26\u4e00\u8fd9\u4e00\u6027\u8d28\u3002<br \/>\n\u6545\u800c\uff0c\u5bf9\u4e8e4 4 1 2\u7684\u60c5\u51b5\uff0c\u7528\u4e0a\u8ff0\u7684\u8d2a\u5fc3\u5f97\u51fa\u7684\u7b54\u6848\u5e94\u5f53\u662f3\uff0c\u7136\u800c\u4e8b\u5b9e\u4e0a\u53ea\u97002\u5373\u53ef\u3002<br \/>\n\u4f46\u662f\uff0c\u524d\u9762\u4ecd\u7136\u6709\u4e00\u4e2a\u7ed3\u8bba\u662f\u6b63\u786e\u7684\u2014\u2014\u4e5f\u5c31\u662f\uff0c\u51fa\u724c\u987a\u5e8f\u4e0d\u5bf9\u7b54\u6848\u9020\u6210\u5f71\u54cd\u3002\u53c8\u8003\u8651\u5230\uff0c\u6570\u7801\u7684\u987a\u5e8f\u5176\u5b9e\u4ec5\u5bf9\u987a\u5b50\u800c\u8a00\u6709\u610f\u4e49\u3002<br \/>\n\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u4ec5\u50a8\u5b58\uff0c\u6570\u91cf\u4e3ak\u7684\u6570\u7801\u6709\u591a\u5c11\u79cd\uff0c\u4ece\u800c\u53ef\u4ee5\u75285^13\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u9884\u5904\u7406\u6bcf\u4e00\u79cd\u6563\u724c\u7684\u72b6\u6001\u3002<br \/>\n\u4f46\u662f\u5982\u679c\u8fd9\u4e48\u505a\u7684\u8bdd\u4f1a\u53d1\u73b0\u8fde\u6837\u4f8b\u4e8c\u90fd\u8fc7\u4e0d\u4e86\u3002\u8fd9\u4e8b\u5b9e\u4e0a\u662f\u56e0\u4e3a\uff0c\u66b4\u529b\u641c\u7d22\u6563\u724c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u5b8c\u5168\u4e0d\u53ef\u63a5\u53d7\u7684\u3002<br \/>\n\u8003\u8651\u5230\u72b6\u6001\u6570\u6781\u5c11\uff0c\u53ef\u4ee5\u8bb0\u5fc6\u5316\u641c\u7d22\u6765\u5b8c\u6210\u9884\u5904\u7406\u3002<br \/>\n\u7528f[i][j][k][l]\u8868\u793a\uff0c\u6709i\u4e2a1\uff0cj\u4e2a2\uff0ck\u4e2a3\uff0cl\u4e2a4\u65f6\u7684\u6700\u5c0f\u89e3\u51b3\u82b1\u8d39\u5373\u53ef\u3002<br \/>\n\u51e0\u4e2a\u5751\u70b9\uff1a<br \/>\n1.\u51fa\u987a\u5b50\u7684\u65f6\u5019\u5e94\u5f53\u662f-=,+=\u800c\u975e\u76f4\u63a5\u8d4b\u503c\u3002<br \/>\n2.\u9884\u5148\u5224\u53cc\u738b\u4ee5\u540e\u5e94\u5f53\u8ba1\u7b97\u82b1\u8d39\u3002<br \/>\n3.\u51fa\u987a\u5b50\u7684\u65f6\u5019\uff0c\u5728\u904d\u5386\u5230\u957f\u5ea6\u6ca1\u8fbe\u5230\u8981\u6c42\u7684\u533a\u95f4\u7684\u65f6\u5019\u4e5f\u5e94\u5f53\u5148\u5c06\u5176\u6e05\u96f6\u7136\u540e\u5728\u904d\u5386\u4e4b\u540e\u52a0\u56de\u53bb\u3002<br \/>\n4.\u6ce8\u610f\u56db\u5e26\u4e8c\u7684\u5404\u79cd\u62c6\u6cd5\uff1a\u7406\u8bba\u4e0a\u5e94\u5f53\u6709\\(C_{4}^{2}+C_{3}^{2}\\)\u79cd\uff0c\u5c11\u4e00\u79cd\u90fd\u4e0d\u884c\uff0c\u4f8b\u5982\uff1a\u4e24\u7ec4\u4e09\u5f20\u548c\u4e24\u7ec4\u56db\u5f20\u53ef\u4ee5\u628a\u4e24\u7ec4\u4e09\u5f20\u62c6\u5f00\u6765\u6253\u3002<br \/>\n\u771f\u53ef\u4ee5\u8bf4\u662f\u4e27\u5fc3\u75c5\u72c2\u7684\u6a21\u62df\u9898\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"cpp\">#include&lt;iostream&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;cstring&gt;\r\nusing namespace std;\r\n#define dfs(X) X.srch()\r\n\/\/\u6240\u6709\u6570+10\u4e4b\u540emod13,13\u5c0f\u738b,14\u5927\u738b\u3002 \r\ninline int Max(int A,int B){\r\n    return A&gt;B?A:B;\r\n}\r\ninline int Min(int A,int B){\r\n    return A&lt;B?A:B;\r\n}\r\nstruct statue;\r\nint n,ans=0x3f3f3f3f,f[14][14][9][7];\r\nint CNT[4]={0,0,0,0};\r\nstruct statue{\r\n    int cst;\r\n    int a[15];\r\n    inline void init(){\r\n        for(int i=0;i&lt;15;++i){\r\n            a[i]=0;\r\n        }\r\n    }\r\n    inline statue(int cstin){\r\n        cst=cstin;\r\n    }\r\n    inline void srch(){\r\n        \/*\r\n        for(int i=0;i&lt;15;++i){\r\n            printf(\"%d \",a[i]);\r\n        }\r\n        printf(\"\\n\");\r\n        *\/\r\n        statue nw(cst+1);\r\n        for(int i=0;i&lt;15;++i){\r\n            nw.a[i]=a[i];\r\n        }\r\n        for(int i=0;i&lt;12;++i){\r\n            if(a[i]&gt;=3){\r\n                nw.a[i]-=3;\r\n                for(int j=i+1;j&lt;12;++j){\r\n                    if(a[j]&lt;3){\r\n                        break;\r\n                    }\r\n                    nw.a[j]-=3;\r\n                    dfs(nw);\r\n                }\r\n                for(int j=i+1;j&lt;12;++j){\r\n                    if(a[j]&lt;3){\r\n                        break;\r\n                    }\r\n                    nw.a[j]+=3;\r\n                }\r\n                nw.a[i]+=3;\r\n            }\r\n            if(a[i]&gt;=2){\r\n                nw.a[i]-=2;\r\n                for(int j=i+1;j&lt;12;++j){\r\n                    if(a[j]&lt;2){\r\n                        break;\r\n                    }\r\n                    nw.a[j]-=2;\r\n                    if(j-i&lt;2){\r\n                        continue;\r\n                    }\r\n                    dfs(nw);\r\n                }\r\n                for(int j=i+1;j&lt;12;++j){\r\n                    if(a[j]&lt;2){\r\n                        break;\r\n                    }\r\n                    nw.a[j]+=2;\r\n                }\r\n                nw.a[i]+=2;\r\n            }\r\n            if(a[i]&gt;=1){\r\n                --nw.a[i];\r\n                for(int j=i+1;j&lt;12;++j){\r\n                    if(a[j]&lt;1){\r\n                        break;\r\n                    }\r\n                    --nw.a[j];\r\n                    if(j-i&lt;4){\r\n                        continue;\r\n                    }\r\n                    dfs(nw);\r\n                }\r\n                for(int j=i+1;j&lt;12;++j){\r\n                    if(a[j]&lt;1){\r\n                        break;\r\n                    }\r\n                    ++nw.a[j];\r\n                }\r\n                ++nw.a[i];\r\n            }\r\n        }\r\n        CNT[0]=CNT[1]=CNT[2]=CNT[3]=0;\r\n        for(int i=0;i&lt;15;++i){\r\n        \t++CNT[a[i]-1];\r\n\t\t}\r\n\t\tans=Min(ans,cst+f[CNT[0]][CNT[1]][CNT[2]][CNT[3]]);\r\n\/\/\t\tprintf(\"%d:%d %d %d %d\\n\",cst,CNT[0],CNT[1],CNT[2],CNT[3]);\r\n    }\r\n};\r\nint II=0,JJ=0,KK=0,LL=0;\r\ninline int rnw(int A,int B,int C,int D){\r\n\tif(A&lt;0||B&lt;0||C&lt;0||D&lt;0||A&gt;13||B&gt;13||C&gt;8||D&gt;6){\r\n\t\treturn 0;\r\n\t}\r\n    f[A][B][C][D]=Min(f[A][B][C][D],f[II][JJ][KK][LL]+1);\r\n    return 0;\r\n}\r\ninline void prpr(){\r\n    memset(f,0x3f,sizeof(f));\r\n    f[0][0][0][0]=0;\r\n    for(int i=0;i&lt;=13;++i){\r\n        for(int j=0;j&lt;=13;++j){\r\n            for(int k=0;k&lt;=8;++k){\r\n                for(int l=0;l&lt;=6;++l){\r\n\/\/                \tprintf(\"%d %d %d %d\\n\",i,j,k,l);\r\n                    II=i,JJ=j,KK=k,LL=l;\r\n                    rnw(i,j,k,l+1);\r\n                    rnw(i+2,j,k,l+1);\r\n                    rnw(i,j+1,k,l+1);\r\n                    rnw(i-1,j,k+1,l+1),rnw(i+1,j-1,k+1,l+1),rnw(i,j-1,k,l+2),rnw(i+1,j,k-1,l+2),rnw(i-1,j+1,k-1,l+2),rnw(i,j-2,k+2,k+1);\r\n                    rnw(i,j+2,k,l+1);\r\n                    rnw(i,j,k,l+2);\r\n                    rnw(i-1,j+1,k+1,l+1),rnw(i-1,j-1,k+1,l+2),rnw(i-2,j,k+2,l+1);\r\n                    \r\n                    rnw(i,j,k+1,l);\r\n                    rnw(i+1,j,k+1,l);\r\n                    rnw(i,j+1,k+1,l);\r\n                    \r\n                    rnw(i,j+1,k,l);\r\n                    \r\n                    rnw(i+1,j,k,l);\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\nvoid init(){\r\n    ans=0x3f3f3f3f;\r\n    int x,xx;\r\n    statue s(0);\r\n    s.init();\r\n    for(int i=1;i&lt;=n;++i){\r\n        scanf(\"%d%d\",&amp;x,&amp;xx);\r\n        ++s.a[(!x)?(12+xx):((x+10)%13)];\r\n    }\r\n    if(s.a[13]&amp;&amp;s.a[14]){\r\n        s.a[13]=s.a[14]=0;\r\n        ++s.cst;\r\n        dfs(s);\r\n        --s.cst;\r\n        s.a[13]=s.a[14]=1;\r\n    }\r\n    dfs(s);\r\n    printf(\"%d\\n\",ans);\r\n}\r\nint main(){\r\n\tprpr();\r\n    int T;\r\n    scanf(\"%d%d\",&amp;T,&amp;n);\r\n    while(T--){\r\n        init();\r\n    }\r\n    return 0;\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\uff0c\u6211\u4eec\u6ce8\u610f\u5230\u82b1\u8272\u5bf9\u4e8e\u6597\u5730\u4e3b\u4e0d\u4f1a\u9020\u6210\u4efb\u4f55\u5f71\u54cd\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5ffd\u89c6\u6389\u82b1\u8272\u8fd9\u4e2a\u4fe1\u606f\u3002 \u7136\u540e\uff0c\u6211\u4eec\u5c06\u5269\u4f59\u7684\u4fe1\u606f\uff0c\u4f9d\u636e &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/SmokeyDays.top\/wordpress\/2018\/12\/08\/lp2540-noip2015-%e6%96%97%e5%9c%b0%e4%b8%bb%e5%a2%9e%e5%bc%ba%e7%89%88\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201clp2540 NOIP2015 \u6597\u5730\u4e3b\u589e\u5f3a\u7248\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,34,35,25,6,36,5],"tags":[],"_links":{"self":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/462"}],"collection":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/comments?post=462"}],"version-history":[{"count":2,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/462\/revisions"}],"predecessor-version":[{"id":464,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/462\/revisions\/464"}],"wp:attachment":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/media?parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/categories?post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/tags?post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}